Search code examples
laravelmessagestatuslang

Laravel 5 new custom message in lang folder


That later different languages ​​can be used, i would like want to save status and success messages in a central file and output them by the respective controller. Currently I'm still doing that in each controller extra.

At the moment:

return back()->with('status', 'Thanks for contacting us!');

Solution

  • Manually insert all the messages in directory resources > lang > en > messages.php , or create any other language folder you might want.

    And then you can use it with this Lang::get('messages.success');

    *use this in your controller use Illuminate\Support\Facades\Lang;

    In your case like this: return back()->with('status', Lang::get('messages.success'));

    An example of messages.php would be:

    return [
    
        'success' => 'your success message.',
        'success1' => 'your success1 message.'
    ];