我试图将现有的php网站转换为Laravel。 旧的PHP有一个脚本运行URL的任何多层子目录。
例如:
/foods/fruits/
/foods/fruits/apples/
/foods/fruits/apples/granny_smith
所有脚本都是由一个脚本管理的,这些脚本都是有意义的,因为它们都来自同一个分层数据库表并且逻辑是相同的。
但我没有看到使用Laravel路由的方法。 Laravel有可能吗?
答案 0 :(得分:1)
我明白了。
Route::get('fooditem/{food}', 'FoodCategoryController@show')
->where('food', '[a-z\_\/]+');
答案 1 :(得分:0)
我认为你要找的是Route::group()
:
//Note: 'middleware' and 'as' are optional.
Route::group(['prefix' => 'foods/fruits', 'middleware' => ['jwt.auth'], 'as' => 'fruits.'], function () {
Route::group(['prefix' => 'apples', 'as' => 'apples.'], function () {
Route::get('/', ['as' => 'list', 'uses' => 'FruitsController@index']);
Route::get('{type}', ['as' => 'show', 'uses' => 'FruitsController@show']);
});
});
$ php artisan route:list
+--------+----------+---------------------------------------+---------------------------------+-----------------------------------------------------------------------------+----------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+---------------------------------------+---------------------------------+-----------------------------------------------------------------------------+----------------------------------------------+
| | GET|HEAD | foods/fruits/apples | fruits.apples.list | App\Http\Controllers\FruitsController@index | jwt.auth |
| | GET|HEAD | foods/fruits/apples/{type} | fruits.apples.show | App\Http\Controllers\FruitsController@show | jwt.auth |
+--------+----------+---------------------------------------+---------------------------------+-----------------------------------------------------------------------------+----------------------------------------------+