Reputation: 9
I need to localize the API web application, especially the auth pages in the lang directory but I have a problem with how to use the route in auth.php instead of api.php in the routes directory.
Note that I used breeze package.
middleware -> SetAppLang.php
public function handle(Request $request, Closure $next): Response
{
if (! in_array($request->segments(1), config('app.available_locales'))) {
abort(404);
}
App::setLocale($request->segments(1));
return $next($request);
}
bootstrap\app.php
'languages'=>App\Http\Middleware\SetAppLang::class,
config\app.php
'available_locales' => [
'en',
'ar'
],
routes\auth.php
Route::middleware(['auth','languages'])->prefix('{locale}')->group(function () {
Route::get('verify-email', EmailVerificationPromptController::class)
->name('verification.notice');
.
.
.
});
I tried using middleware in api.php but I failed, can anyone help?
Upvotes: 0
Views: 32