1 回答
TA贡献1784条经验 获得超7个赞
Laravel 8 更新了路由的编写方式
在 laravel 8 中你需要使用像
use App\Http\Controllers\SayhelloController; Route::get('/users/{name?}' , [SayhelloController::class,'index']);
或者
Route::get('/users', 'App\Http\Controllers\UserController@index');
如果你想使用旧的方式
然后在RouteServiceProvider.php
添加这一行
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers'; // need to add in Laravel 8
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace) // need to add in Laravel 8
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace) // need to add in Laravel 8
->group(base_path('routes/web.php'));
});
}
然后你可以使用像
Route::get('/users/{name?}' , [SayhelloController::class,'index']);
Route::resource('/users' , SayhelloController::class);
或者
Route::get('/users', 'UserController@index');
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报