为什么在laravel 5.3中的RouteCollection.php第161行中出现NotFoundHttpException

时间:2016-09-02 06:58:33

标签: laravel exception routes

我想将一些表单信息提交到我的表中,但是这个错误正在显示,如果我Route::resource('userinfo','infoController@index');错误消失了,但我无法插入数据,那将是什么解决方案。

我的控制器

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\infomodel;

class infoController extends Controller
{
 public function index()
 {
   $alldata = infomodel::all();
   return $alldata;
 }

 public function create()
 {
    return view('userinfo.create');
 }

 public function store(Request $request)
 {
    $input = $request->all();
    infomodel:: create($input);
    return redirect('infomodel');
 }
}

我的模特

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class infomodel extends Model
{
    Protected $table = "info";
    protected $fillable = ['name', 'email', 'age', 'hometown'];
}

我的路线web.php

<?php
Route::resource('userinfo','infoController');

Route::get('/solid', function () {
    return view('solid.index');
});

这是查看create.blade.php

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <title>Userinfo</title>
</head>
<body>

<div class="container" style="width:350px; margin:0 auto;
margin-top:25px;">

{!! Form::open(['route' => 'userinfo.store']) !!}


<div class="form-group">
    <label for="name">Enter Your name</label>
    <input type="text" class="form-control" name="name" placeholder="Enter name">

  </div>

  <div class="form-group">
    <label for="email">Email address</label>
    <input type="email" class="form-control" name= "email" placeholder="Enter email">

  </div>


  <div class="form-group">
    <label for="age">Age</label>
    <input type="number" class="form-control" name="age" placeholder="Enter age">

  </div>

<div class="form-group">
    <label for="exampleInputEmail1">Hometown</label>
    <input type="text" class="form-control" name="hometown" placeholder="Enter hometown">

  </div>

  <button type="submit" class="btn btn-primary">Submit</button>

  </div>

{!! Form::close() !!}

</div>


</body>
</html>

1 个答案:

答案 0 :(得分:2)

问题在于您的store方法

public function store(Request $request)
{
    $input = $request->all();
    infomodel:: create($input);
    return redirect('infomodel');
}

您将用户重定向到不存在的路由infomodel

试试这个

public function store(Request $request)
{
    $input = $request->all();
    infomodel:: create($input);

    // You can try 'return back()' as well
    return redirect()->route('userinfo.index');
}