一,相关文档:
https://learnku.com/docs/laravel/10.x/routing/14845
二,查看所有注册的路由
1,查看路由:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan route:list
GET|HEAD / ...............................................................................................................................................................
POST _ignition/execute-solution ........................................................ ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
GET|HEAD _ignition/health-check .................................................................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
POST _ignition/update-config ................................................................. ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
GET|HEAD api/user ........................................................................................................................................................
GET|HEAD container/test ..................................................................................................................................................
GET|HEAD news/cache ................................................................................................................................. NewsController@cache
GET|HEAD news/home ................................................................................................................................... NewsController@home
GET|HEAD news/homejson ........................................................................................................................... NewsController@homejson
GET|HEAD news/list ................................................................................................................................... NewsController@list
GET|HEAD news/log ..................................................................................................................................... NewsController@log
GET|HEAD news/req ..................................................................................................................................... NewsController@req
GET|HEAD news/res ..................................................................................................................................... NewsController@res
GET|HEAD news/trans ................................................................................................................................. NewsController@trans
GET|HEAD sanctum/csrf-cookie ........................................................................... sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
GET|HEAD {fallbackPlaceholder} ...........................................................................................................................................
2,加-v,查看路由同时显示用到的中间件:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan route:list -v
GET|HEAD / ...............................................................................................................................................................
⇂ web
POST _ignition/execute-solution ........................................................ ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
⇂ Spatie\LaravelIgnition\Http\Middleware\RunnableSolutionsEnabled
GET|HEAD _ignition/health-check .................................................................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
⇂ Spatie\LaravelIgnition\Http\Middleware\RunnableSolutionsEnabled
POST _ignition/update-config ................................................................. ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
⇂ Spatie\LaravelIgnition\Http\Middleware\RunnableSolutionsEnabled
GET|HEAD api/user ........................................................................................................................................................
⇂ api
⇂ App\Http\Middleware\Authenticate:sanctum
GET|HEAD container/test ..................................................................................................................................................
⇂ web
GET|HEAD news/cache ................................................................................................................................. NewsController@cache
⇂ web
GET|HEAD news/home ................................................................................................................................... NewsController@home
⇂ web
GET|HEAD news/homejson ........................................................................................................................... NewsController@homejson
⇂ web
GET|HEAD news/list ................................................................................................................................... NewsController@list
⇂ web
GET|HEAD news/log ..................................................................................................................................... NewsController@log
⇂ web
GET|HEAD news/req ..................................................................................................................................... NewsController@req
⇂ web
⇂ App\Http\Middleware\CheckIp
GET|HEAD news/res ..................................................................................................................................... NewsController@res
⇂ web
GET|HEAD news/trans ................................................................................................................................. NewsController@trans
⇂ web
GET|HEAD sanctum/csrf-cookie ........................................................................... sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
⇂ web
GET|HEAD {fallbackPlaceholder} ...........................................................................................................................................
⇂ web
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/22/laravel-lu-you-zu-10-27/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: [email protected]
三,使用路由组
1,基于controller分组:
Route::controller(NewsController::class)->group(function () {
Route::get('/news/home', 'home');
Route::get('/news/homejson', 'homejson');
});
2,基于前缀分组
Route::prefix('news')->group(function () {
Route::get('/home', [NewsController::class,'home']);
Route::get('/list', [NewsController::class,'list']);
});
3,基于路由中间件
Route::middleware(['first', 'second'])->group(function () {
Route::get('/', function () {
// 使用第一个和第二个中间件。。。
});
Route::get('/user/profile', function () {
// 使用第一个和第二个中间件。。。
});
});
四,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0
标签:laravel,web,HEAD,GET,10.27,ignition,NewsController,news,路由
From: https://www.cnblogs.com/architectforest/p/17781571.html