使用表单

时间:2016-10-11 14:01:37

标签: php laravel-routing laravel-5.3

表格中的邮政路线错误。点击“提交”按钮后,将我带到页面。

 NotFoundHttpException in RouteCollection.php line 161:
    in RouteCollection.php line 161
    at RouteCollection->match(object(Request)) in Router.php line 780
    at Router->findRoute(object(Request)) in Router.php line 610
    at Router->dispatchToRoute(object(Request)) in Router.php line 596
    at Router->dispatch(object(Request)) in Kernel.php line 267
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
    at Pipeline->then(object(Closure)) in Kernel.php line 149
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
    at Kernel->handle(object(Request)) in index.php line 54

Create.Blade.PHP。我也想知道方法是否正确定义。

<form action="POST" method="/users">
 {{ csrf_field() }}

  Name:<input type="text" name="name"></br>
  Email:<input type="text" name="email"></br>
  Password:<input type="text" name="password"></br>
  Submit:<input type="submit" value="submit">
</form>

路由文件

Route::GET('/', function () {
    return View('hello');
});

Route::get('users/create',['uses'=>'UsersController@create']);
Route::post('users',['uses'=>'UsersController@store']);

检查注册路线“php artisan route:list -v”显示两条路线都已正确注册。

UsersController.PHP

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;



class UsersController extends Controller
{
    public function index()
    {
      $users=[
      '0'=>[
      'name'=>'arun',
      'email'=>'ak@gmail.com',
      'location'=>'india'],
      '1'=>[
      'name'=>'kaushik',
      'email'=>'arunk@gmail.com',
      'location'=>'india'],
    ];

      return View('admin.users.index',Compact('users'));
    }


     public function create()
    {
      return View('admin.users.create');
    }

    public function store(Request $request)
   {
     return $request->all();

   }
}

最后,我对.htaccess文件进行了任何更改,这是一个新安装。 我已成功正确运行PHP工匠迁移。

1 个答案:

答案 0 :(得分:0)

好像你刚刚切换了表单的action和method属性。

<form action="POST" method="/users">
 {{ csrf_field() }}

  Name:<input type="text" name="name"></br>
  Email:<input type="text" name="email"></br>
  Password:<input type="text" name="password"></br>
  Submit:<input type="submit" value="submit">
</form>