I am developing a localization in Laravel 10. When I triggered to change the flag of Localization Then Error Show in Page.
Can anyone tell Just where is the problem ?
Error Message
Call to undefined method App\Http\Middleware\LocalizationMiddleware::setLanguage() in Localization
Here is my LocalizationController
Controller
{
App::setLocale($locale);
Session::put('locale', $locale);
return redirect()->back();
}
Here is my LocalizationMiddleware
public function handle(Request $request, Closure $next): Response
{
// Set Locale in this Middleware
App::setLocale(session()->get('selected_language') ?? 'en');
return $next($request);
}
Here is my route
Route::get('locale/{locale}',[LocalizationMiddleware::class, 'setLanguage'])->name('locale');
And here is my Blade code
<div class="dropdown ms-1 topbar-head-dropdown header-item">
<button type="button" class="btn btn-icon btn-topbar btn-ghost-secondary rounded-circle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img id="header-lang-img" src="{{ asset('/') }}els/images/flags/us.svg" alt="Header Language" height="20" class="rounded">
</button>
<div class="dropdown-menu dropdown-menu-end">
<!-- English language -->
<a href="locale/en" class="dropdown-item notify-item language py-2" data-lang="en" title="English">
<img src="{{ asset('/') }}els/images/flags/us.svg" alt="user-image" class="me-2 rounded" height="18">
<span class="align-middle">English</span>
</a>
<!-- German Language -->
<a href="{{ url('locale/de') }}" class="dropdown-item notify-item language" data-lang="gr" title="German">
<img src="{{ asset('/') }}els/images/flags/germany.svg" alt="user-image" class="me-2 rounded" height="18"> <span class="align-middle">Deutsche</span>
</a>
</div>
</div>
I don't understand why is this happening.