mojtabaahn / laravel-controller-routes
为Laravel添加以控制器为中心的路由
1.0.0-alpha.1
2020-08-18 13:16 UTC
Requires
- php: ^7.4
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-09 04:12:01 UTC
README
要求
此包需要 PHP 7.4 或更高版本。
安装
您可以通过composer安装此包
composer require mojtabaahn/laravel-controller-routes
用法
<?php // routes/web.php use MojtabaaHN\LaravelControllerRoutes\Routes; use Illuminate\Support\Facades\Route; Routes::make('UserController')->methods(function (ControllerAwareRouter $router) { $router->get('user/{user}', 'profile')->name('user.profile'); $router->get('user/{user}/post/{post}','post')->name('user.post'); }); // Or Routes::make() ->controller('UserController') ->methods(function (ControllerAwareRouter $router) { $router->get('user/{user}', 'profile')->name('user.profile'); $router->get('user/{user}/post/{post}','post')->name('user.post'); }); // Same as Route::get('user/{user}', 'UserController@profile')->name('user.profile'); Route::get('user/{user}/post/{post}','UserController@posts')->name('user.posts'); // Using RouteRegistrar methods Routes::make() ->prefix('user/{user}') ->name('user.') ->middleware('web') ->controller('UserController') ->methods(function (ControllerAwareRouter $router) { $router->get('/', 'profile')->name('profile'); $router->get('posts','posts')->name('posts'); }); // same as Route::prefix('user/{user}') ->name('user.') ->middleware('web') ->group(function(){ Route::get('/', 'UserController@profile')->name('profile'); Route::get('posts','UserController@posts')->name('posts'); });
测试
composer test
许可证
MIT许可证(MIT)。更多信息请参阅许可证文件。