Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Resource Routes Naming Prefix

I've tow resource routes defined.

Route::resource('p/contacts', 'BaseData\PrivateContactsController');
Route::resource('b/contacts', 'BaseData\ContactController');

My Problem is that both resource group becomes the prefix same prefix (contacts.show, contacts.edit...)

In the Laravel docs I found this way to name the routes

Route::resource('photos', 'PhotoController')->names([
'create' => 'photos.build'
]);

In my eyes this way is very complicated becaus I have to set the prefix for each single route. Is there a better way to set the prefix for all routes of the group?

like image 916
Markus Avatar asked Oct 30 '25 21:10

Markus


1 Answers

Route::resource('p/contacts', 'BaseData\PrivateContactsController',["as"=>"private"]);
Route::resource('b/contacts', 'BaseData\ContactController',["as"=>"normal"]);

this way the urls will stay the same, but the names will have a prefix, for the first resource controller

private.contacts.index or private.contacts.edit

and for the second controller

    normal.contacts.create or normal.contacts.show

for more info check the documentation or this github issue

like image 111
A. Dabak Avatar answered Nov 02 '25 10:11

A. Dabak