German
German

Reputation: 137

Localize flash messages?

Please advise how to localize flash messages? I followed laracast series: https://laracasts.com/series/build-project-flyer-with-me/episodes/9

    Auth::login(User::firstOrCreate($data));

    flash()->success('flash.success', 'flash.login');
    return redirect($this->redirectPath());`

Upvotes: 2

Views: 2077

Answers (3)

Ahmed Ali
Ahmed Ali

Reputation: 11

You can do that

in your controller

return redirect('/login')->with('success', __('auth.registered'));

and in lang files for example using En and Ar

go to lang/en/auth and create your status message

'registered' => 'Your message in English'

go to lang/ar/auth and create your status message

'registered' => 'Your message in Arabic'

then in your blade, you retrieve the coming message from the controller

@if(session('success'))
    <div class="alert alert-success" role="alert">
        <div class="alert-body">
            {{session('success')}}
        </div>
    </div>
@endif

Upvotes: 0

Mirsad Batilovic
Mirsad Batilovic

Reputation: 441

return redirect('/login')->with('status', trans('auth.registered'));

In resources/lang/es/auth.php

return [
     ...
     'registered' => "Your message translated on Spanish.",
];

Upvotes: 3

Suresh Velusamy
Suresh Velusamy

Reputation: 2398

Go through about localization Laravel Localization

You can find more information

Upvotes: 0

Related Questions