arifmahmudrana/laravel-resource-route-wildcard-alias

Laravel 资源路由通配符别名,用于在路由模型绑定中使用别名和相同的模型名称

v1.0.0 2016-02-12 17:50 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:38:39 UTC


README

使用方法

步骤 1:通过 Composer 安装

composer require arifmahmudrana/laravel-resource-route-wildcard-alias

步骤 2:添加服务提供者

将服务提供者添加到 config/app.php 文件中的 providers 数组中。例如

AriMahmudRana\laravelResourceRouteWildcardAlias\LaravelResourceRouteWildcardAliasServiceProvider::class

这样就完成了。

示例

使用别名创建资源路由。

Route::group(['middleware' => ['web']], function () {
    Route::resource('album.photo.hello', 'PhotoController', ['alias' => ['album' => 'a', 'photo' => 'p', 'hello' => 'h']]);
});

php artisan route:list 的输出中。

+--------+-----------+------------------------------------+---------------------------+----------------------------------------------+------------+
| Domain | Method    | URI                                | Name                      | Action                                       | Middleware |
+--------+-----------+------------------------------------+---------------------------+----------------------------------------------+------------+
|        | GET|HEAD  | /                                  |                           | Closure                                      |            |
|        | POST      | album/{a}/photo/{p}/hello          | album.photo.hello.store   | App\Http\Controllers\PhotoController@store   | web        |
|        | GET|HEAD  | album/{a}/photo/{p}/hello          | album.photo.hello.index   | App\Http\Controllers\PhotoController@index   | web        |
|        | GET|HEAD  | album/{a}/photo/{p}/hello/create   | album.photo.hello.create  | App\Http\Controllers\PhotoController@create  | web        |
|        | DELETE    | album/{a}/photo/{p}/hello/{h}      | album.photo.hello.destroy | App\Http\Controllers\PhotoController@destroy | web        |
|        | PUT|PATCH | album/{a}/photo/{p}/hello/{h}      | album.photo.hello.update  | App\Http\Controllers\PhotoController@update  | web        |
|        | GET|HEAD  | album/{a}/photo/{p}/hello/{h}      | album.photo.hello.show    | App\Http\Controllers\PhotoController@show    | web        |
|        | GET|HEAD  | album/{a}/photo/{p}/hello/{h}/edit | album.photo.hello.edit    | App\Http\Controllers\PhotoController@edit    | web        |
+--------+-----------+------------------------------------+---------------------------+----------------------------------------------+------------+

许可

在 MIT 许可下发布,请参阅 LICENSE。