gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:47:29 27 4
gpt4 key购买 nike

我已经开始研究 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com