提交表单后,我收到错误消息“抱歉,找不到您要查找的页面。”

我是 laravel 的新手,现在我在做一些小项目。我有一个表单,在按下提交按钮后,我收到此错误消息“抱歉,找不到您要查找的页面。”


我的代码有什么问题吗?请帮我解决这个问题,这样我就可以继续这个项目。


谢谢指教


查看刀片,我将其命名为 index.blade.php


<div class="col m7 s12">

        <form method="submit" action="post">

          {{ csrf_field() }}

          <div class="card-panel">

            <h5>Please Fill Out This Form</h5>

            <div class="input-field">

              <input type="text" name="name" id="name" required class="validate">

              <label for="name">Name</label>

            </div>

            <div class="input-field">

              <input type="email" name="email" id="email" class="validate">

              <label for="email">Email</label>

            </div>

            <div class="input-field">

              <input type="text" name="phone" id="phone">

              <label for="phone">Phone</label>

            </div>

            <div class="input-field">

              <textarea name="message" id="message" class="materialize-textarea"></textarea>

              <label for="message">Message</label>

            </div>

            <button type="submit" class="btn" blue darken-1>Send</button>

          </div>

        </form>

控制器,我将它命名为 LayoutController


<?php


namespace App\Http\Controllers;


use Illuminate\Http\Request;

use DB;


class LayoutController extends Controller


    {

        /**

         * Display a listing of the resource.

         *

         * @return \Illuminate\Http\Response

         */

        public function index()

        {

            //

            return view('layouts/index');

        }


        public function submit(Request $request)

        {

            $name = $req->input('name');

            $email = $req->input('email');

            $phone = $req->input('phone');

            $message = $req->input('message');


            $data = array('name'=>$name,"email"=>$email,"phone"=>$phone,"message"=>$message);


            $data->save();

            return Redirect::to('/layouts/index');

        }

路由 web.php


Route::get('/', 'LayoutController@index');


Route::post('/submit', 'LayoutController@submit');


开满天机
浏览 148回答 3
3回答

缥缈止盈

形式方法应该是POST和action将是您的路线:<form&nbsp;method="POST"&nbsp;action="{{&nbsp;url('/submit')&nbsp;}}">

守着一只汪

尝试这个 :<form&nbsp;method="POST"&nbsp;action="{{&nbsp;route('submit')&nbsp;}}">

烙印99

你的表单方法应该是POST,动作应该是/submit<form method="POST" action="/submit">&nbsp; &nbsp; {{ csrf_field() }}&nbsp; &nbsp; <div class="card-panel">&nbsp; &nbsp; &nbsp; <h5>Please Fill Out This Form</h5>&nbsp; &nbsp; &nbsp; <div class="input-field">&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="name" id="name" required class="validate">&nbsp; &nbsp; &nbsp; &nbsp; <label for="name">Name</label>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="input-field">&nbsp; &nbsp; &nbsp; &nbsp; <input type="email" name="email" id="email" class="validate">&nbsp; &nbsp; &nbsp; &nbsp; <label for="email">Email</label>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="input-field">&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="phone" id="phone">&nbsp; &nbsp; &nbsp; &nbsp; <label for="phone">Phone</label>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="input-field">&nbsp; &nbsp; &nbsp; &nbsp; <textarea name="message" id="message" class="materialize-textarea"></textarea>&nbsp; &nbsp; &nbsp; &nbsp; <label for="message">Message</label>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <button type="submit" class="btn" blue darken-1>Send</button>&nbsp; &nbsp; </div></form>
打开App,查看更多内容
随时随地看视频慕课网APP