Route & Prefix has same name. I'm not able to get ID
parameter of {hotel}
which is empty as i mention below in image. What is the best way to use prefix and resource controller with same name?
Routes/web.php
Route::namespace('Admin\Hotel')->prefix('hotels')->name('hotels.')->group(function () {
Route::resource('/', 'HotelController');
Route::resource('rooms', 'RoomController');
Route::resource('rooms/gallery', 'RoomGalleryController');
});
php artisan route:list
for Route::resource('/', 'HotelController')
I have the same scenario in mixing Group
and Resource
and I can't get the ID group (which in this case Hotel
).
Here's how I did it in (Laravel 5.5):
Route::group(['prefix' => 'hotel/{hotel}'], function () {
Route::resource('/', 'HotelController');
Route::resource('rooms', 'RoomController');
Route::resource('rooms/gallery', 'RoomGalleryController');
});
it's because resource method will automaticly add the prefix and the named routes with the first parameter you give, hotel
in your case.
So you can do something like this :
Route::namespace('Admin\Hotel')->group(function () {
Route::resource('hotels', 'HotelController');
});
Or, you can remove group function and directly use resource method.
Route::resource('hotels', 'Admin\Hotel\HotelController');
Or,
Route::namespace('Admin\Hotel')->group(function () {
Route::resource('hotels', 'HotelController');
Route::prefix('hotels')->name('hotels.')->group(function () {
Route::resource('gallery', 'HotelGalleryController');
Route::resource('rooms', 'RoomController');
Route::resource('rooms/gallery', 'RoomGalleryController');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With