RouteCollection.php 第 161 行 Laravel 5.3 中的 NotFoundHttpException
Posted
技术标签:
【中文标题】RouteCollection.php 第 161 行 Laravel 5.3 中的 NotFoundHttpException【英文标题】:NotFoundHttpException in RouteCollection.php line 161 Laravel 5.3 【发布时间】:2017-02-01 07:28:56 【问题描述】:我已经开始研究 laravel 5.3 了。构建一个基本的登录页面。
这是我的 homeController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
$this->middleware('auth');
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
return view('home');
我的 User.php
<?php
namespace App;
use Illuminate\Http\Request
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
之前只有一个 route.php,但现在在 Laravel 5.3 中,路由目录中有 api.php、console 和 web.php,因此我没有找到任何资源来查找添加路由命令的位置。
我在路由文件夹中的 api.php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::get('/user', function (Request $request)
return $request->user();
)->middleware('auth:api');
我在路由文件夹中的 web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/', function ()
return view('welcome');
);
Auth::routes();
Route::get('/home', 'HomeController@index');
Auth::routes();
Route::get('/home', 'HomeController@index');
路由文件夹中的我的 console.php
<?php
use Illuminate\Foundation\Inspiring;
/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of your Closure based console
| commands. Each Closure is bound to a command instance allowing a
| simple approach to interacting with each command's IO methods.
|
*/
Artisan::command('inspire', function ()
$this->comment(Inspiring::quote());
)->describe('Display an inspiring quote');
Route :: get('/', function () return view('welcome'); );
这很好,因为我可以看到主页,但其他路线不起作用。当我点击登录或注册此异常时
【问题讨论】:
【参考方案1】:有关 5.3 路由的更多信息,请关注@matt 发布的此文档。
https://mattstauffer.co/blog/routing-changes-in-laravel-5-3
还阅读了有关laravel 5.3路由here的详细文档。
除非您自定义 laravel 开箱即用的路由合格链接,否则您不应该使用 api.php,以自定义您的路由使用 web.php。
【讨论】:
以上是关于RouteCollection.php 第 161 行 Laravel 5.3 中的 NotFoundHttpException的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5.4 模块:RouteCollection.php 第 161 行中的 NotFoundHttpException
laravel报错,NotFoundHttpException in RouteCollection.php line 161:
laravel框架报NotFoundHttpException in RouteCollection.php line 161:错误怎么办
RouteCollection.php 第 201 行中的 Laravel 5 MethodNotAllowedHttpException:
RouteCollection.php 第 218 行中的 MethodNotAllowedHttpException
Laravel 5 - RouteCollection.php 第 143 行中的 NotFoundHttpException