nasution / laravel-implicit-routes
Laravel 隐式路由,与 CodeIgniter 非常相似。
v0.1.0
2016-08-05 18:30 UTC
This package is auto-updated.
Last update: 2024-09-10 10:11:49 UTC
README
为 Laravel 创建隐式路由。它与 CodeIgniter 路由非常相似。
安装
composer require nasution/laravel-implicit-routes
在 config/app.php
文件的 providers
中注册服务提供者。
Nasution\ImplicitRoutes\ServiceProvider::class,
用法
将 Route::anything()
添加到您的路由文件中。
Route::anything(); Route::get('/', 'HomeController@welcome');
现在,您有权访问任何路径。例如,如果您访问 https:///products/shoes/42
,则等价于
Route::any('products/shoes/{param0}', 'ProductsController@shoes'); class ProductsContoller extends Controller { public function shoes($id) { return $id; // 42 } }
如果您访问没有第二个分段的地址,它将使用 index
方法。例如 https:///products
,则等价于
Route::any('products', 'ProductsController@index'); class ProductsContoller extends Controller { public function index() { // } }
许可证
MIT © Mulia Arifandi Nasution