laravel - RouteCollection.php 第 161 行 Laravel 5.3 中的 NotFoundHttpException

标签 laravel

我已经开始研究 laravel 5.3 了。构建一个基本的登录页面。

这是我的主 Controller

<?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 在 routes 文件夹中

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 在 routes 文件夹中

<?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在route文件夹中

<?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');} );

这工作正常,因为我能够看到主页,但其他路由不工作。当我单击登录或注册时出现此异常

最佳答案

有关 5.3 路由的更多信息,请参阅@matt 发布的文档。

https://mattstauffer.co/blog/routing-changes-in-laravel-5-3

另请阅读 laravel 5.3 路由详情文档 here .

你不应该使用 api.php 除非你正在自定义 laravel 开箱即用的路由限定链接,要自定义你的路由请改用 web.php。

关于laravel - RouteCollection.php 第 161 行 Laravel 5.3 中的 NotFoundHttpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39660731/

相关文章:

javascript - jquery 数据表自定义过滤器

php - Laravel 日志记录不适用于作业处理方法

mysql - 如何使用 Laravel 访问 MariaDB 中的 json 属性?

php - 如何使用 Laravel Eloquent 动态填充复选框

laravel - Guzzle 将证书验证禁用为 false,它有多不安全?

php - 使用 map 和包含的 Laravel 集合

JavaScript 语法错误 : missing

laravel - Eloquent where lower() LIKE 与 PostgreSQL Laravel

php - Laravel Queue - 记住属性(property)状态?

php - 如何在 Laravel 5 中检索 View 名称?