Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

php - Laravel custom action names and route names using a resource controller?

By default Resource controller gives you those Actions and Route names:

ACTION  ROUTE NAME
index   resource.index
create  resource.create
store   resource.store
show    resource.show
edit    resource.edit
update  resource.update
destroy resource.destroy

and want to rename both of them (Actions and Routes names) to:

ACTION  ROUTE NAME
**browse    resource.browse**
create  resource.create
store   resource.store
show    resource.show
edit    resource.edit
update  resource.update
**delete    resource.delete**

And still use a Resource Controllers, like this:

Route::resource('resource', 'ResourceController');

and not a list of GET routes like this:

Route::get('resource', 'ResourceController@index');
Route::get('resource/create', 'ResourceController@index');
...
question from:https://stackoverflow.com/questions/65642130/laravel-custom-action-names-and-route-names-using-a-resource-controller

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is a good solution suggested by Laravel doc:

Route::resource('resource', 'ResourceController', ['names' => [
    'index' => 'resource.browse',
    'delete' => 'resource.delete',
]]);

The rest will have the default names.

Related section in Laravel docs: https://laravel.com/docs/5.2/controllers#restful-naming-resource-routes


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...