laravel 7 implement custom flash message with example – onlinecode
In this post we will give you information about laravel 7 implement custom flash message with example – onlinecode. Hear we will give you detail about laravel 7 implement custom flash message with example – onlinecodeAnd how to use it also give you demo for it if it is necessary.
In this tutorial, We will explain to you how to Implement Custom Flash Messages with Example in laravel. so we will create a custom flash-message using bootstrap without any package.
When the user performs any operation that time it happened a success or fails, We use Custom Flash Messages to show that. so you can follow the below step.
Change default configuration name of Laravel's created_at and updated_at
In this post we will give you information about Change default configuration name of Laravel's created_at and updated_at. Hear we will give you detail about Change default configuration name of Laravel's created_at and updated_atAnd how to use it also give you demo for it if it is necessary.
In this Laravel PHP Tutorial, I will let you know the use of created_at and updated_at column in a database table.
By default, Eloquent automatically maintain the date time value in created_at and updated_at column on your database table. If you do not want for eloquent to maintain created_at and updated_at columns then disable it by adding following property in your model class :
- class Member extends Eloquent {
- protected $table='members';
- public $timestamps= false;
- }
class Member extends Eloquent {
protected $table = 'members';
public $timestamps = false;
}If you want to map Laravel's timestamp from created_at to created_on and updated_at to modified_on then you can override const on your model in following way :
const CREATED_AT = 'created_on'; const UPDATED_AT = 'modified_on';
Now Eloquent will take care of the column "created_on" and "modified_on" on your database table.
How to disable created_at and updated_at timestamps in Laravel Model?
Label :
PHP Laravel PHP Framework How To MVC Web DevelopmentHope this code and post will helped you for implement Change default configuration name of Laravel's created_at and updated_at. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
Create flash messages view filehere, in this step, we will create a flash-message.blade.php file. In this file we will create different alert flash-message codes like success, error, warning, info, and validation error.resources/views/flash-message.blade.php
@if ($message = Session::get('success'))
<div >
<button type="button" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
@if ($message = Session::get('error'))
<div >
<button type="button" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
@if ($message = Session::get('warning'))
<div >
<button type="button" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
@if ($message = Session::get('info'))
<div >
<button type="button" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
@if ($errors->any())
<div >
<button type="button" data-dismiss="alert">×</button>
Please check the form below for errors
</div>
@endif
Use flash-message file in Master fileIn this step, we will include a flash-message.blade.php file in the master file. so you can see the below code.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!-- Styles -->
<link href="/css/app.css" rel="stylesheet">
</head>
<body>
<div >
<div id="app">
@include('flash-message')
@yield('content')
</div>
</div>
<!-- Scripts -->
<script src="/js/app.js"></script>
</body>
</html>
Use flash messages with redirectNow, you can pass different types of error messages in the controller file. so you can see below different types of error messages.
Redirect with Success Flash Message
return redirect()->route()->with('success','here your success message');
Redirect with error Flash Message
return redirect()->route()->with('error','here your error message');
Redirect with warning Flash Message
return redirect()->route()->with('wanrning','Here your warning message');
Redirect with info Flash Message
return redirect()->route()->with('info','Here your info message');
Redirect with Validation Error Flash Message
public function store(Request $request)
{
$request->validate([
'txtFirstName'=>'required',
'txtLastName'=> 'required',
'txtAddress' => 'required'
]);
.....
}
Hope this code and post will helped you for implement laravel 7 implement custom flash message with example – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs