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 關注
- 238 瀏覽
添加回答
舉報