So I have creted my group in web.php
`Route::redirect('/', '/it');
Route::group(['prefix' => '{locale}'], function () {
Route::get('/','HomeController@index');
Route::get('/business', 'BusinessViewController@index');
Route::post('business', 'BusinessViewController@store');
Route::get('/business/create', 'BusinessViewController@create');
Route::get('/business/{slug}', 'BusinessViewController@show');
Route::get('/contact', 'ContactController@index');
}); `
Also created the middleware SetLanguage.php:
public function handle($request, Closure $next) { App::setLocale($request->segment(1)); URL::defaults(['locale' => $request->segment(1)]); return $next($request); }
I addeed the middleware class to middlewareGroups - "web" in Kernal.php
Now how should I add href links in blade.php?
<a href="/business">{{__('common.list')}}</a>
This line does not bring to correct language.
I do not want session, I want that the language is in the url: www.weburl.com /en/ something
So I found the solution, what you need to route the link. so like this:
<a href="{{ route('contact', app()->getLocale()) }}">{{__('common.contact_us')}}</a>
and to work this you have to add the name to the Route in web.php like this:
Route::get('/contact', 'ContactController@index')->name('contact');
if you do not add the name, it will say Route not found.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community