Laravel custom messages in lang folder

613 0 0 0

Last Updated : 2024-03-29 09:50:58

In this snippet I will teach you how to use custom messages in laravel lang folder to use in your controller or in your blade views

In this snippet I will teach you how to create cutom messages in laravel and use it antywhere like this 


1- you can insert all your custom messages in this directory resources > lang > en > messages.php or you can create any other language folder you want .


2- this messages file in lang folder will be like this one


<?php

return [

/*
|--------------------------------------------------------------------------
| Messages file
|--------------------------------------------------------------------------
|
*/

'success' => 'your success message.',
'success1' => 'your success1 message.'

];

3- Use these messages in your controller like this


use Illuminate\Support\Facades\Lang;  // Don't forget to include this line at the top of your controller 

// Use the message like this
return redirect()->back()->with('adminLoginMSG', Lang::get('messages.success'));

4- you can use these messages in the blade view like ths


echo __('messages.success');

 

Mahmoud Anwar

Mahmoud Anwar

Back End Developer with a passion for developing innovative web applications that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. Also has the proven ability to motivate, educate, and collaborate effectively to build web applications and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs, highlight their core competencies, and further their success.