Named route doesn't work Hi,
I have created routing, which I called 'saveObject' but it doesnt work.
the url i am reciving is: /admin/routes.saveobject
and I would like it to be: /admin/saveobject
how can I fix this?
here is routing from web.php
Route::match(['GET', 'POST'], trans('routes.saveobject').'/{id?}','BackendController@saveObject')->name('saveObject')->middleware('CheckOwner');
and the view file
<li><a href="{{ route('saveObject') }}">Add a new tourist object</a></li>
your web.php
should be like
trans('saveobject').'/{id?}','BackendController@saveObject')->name('saveObject')->middleware('CheckOwner');
As far as I know you cannot use variables in routes like that I'm afraid (how would you cache it?)
Try this instead
Route::match(['GET', 'POST'], '{trans}, /{id?}','BackendController@saveObject')->name('saveObject')->middleware('CheckOwner');
<li><a href="{{ route('saveObject', ['trans' => trans('routes.saveobject')) }}">Add a new tourist object</a></li>
I have just started learning programming, I don't quite understand which variable should I not use?
Thank you,
your solution works, but here is one thing I dont understand. I have another routes witch are very similar and works fine
Route::get(trans('routes.object').'/{id}','FrontendController@object')->name('object');
Route::post(trans('routes.roomsearch'),'FrontendController@roomsearch')->name('roomSearch');
Route::get(trans('routes.room').'/{id}','FrontendController@room')->name('room');
Route::get(trans('routes.article').'/{id}','FrontendController@article')->name('article');
Route::get(trans('routes.person').'/{id}','FrontendController@person')->name('person');
Ok
i found bug - the problem was in the routes.php file in the lang directory.
It was that I forgot about case sensitivity.
here is routes.php code
<?php
return [
'saveObject' => 'zapiszobiekt',
]
?>
should be like this:
<?php
return [
'saveobject' => 'zapiszobiekt',
]
?>
I found the time to test my hypotesis, and I was right.
Try running php artisan route:cache. Now try and change the locale and access the route for that language. You will get a 404, as it is only cached with the default locale
Consider using a package for this that can handle it correctly.
https://github.com/codezero-be/laravel-localized-routes#-translate-routes
Please sign in or create an account to participate in this conversation.