Raj Technologies
Published in

Raj Technologies

Laravel Implement Flash Messages with an example using Laravel Blade X

First, install Laravel Below Link more Details

1)success

2)error

3)warning

4)info

5)validation error

Make Components

php artisan make:component Alert

resources/views/components/alert.blade.php

@if ($message = Session::get(‘success’))
<div class=”alert alert-success alert-block”>
<button type=”button” class=”close” data-dismiss=”alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘error’))
<div class=”alert alert-danger alert-block”>
<button type=”button” class=”close” data-dismiss=”alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘warning’))
<div class=”alert alert-warning alert-block”>
<button type=”button” class=”close” data-dismiss=”alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘info’))
<div class=”alert alert-info alert-block”>
<button type=”button” class=”close” data-dismiss=”alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($errors->any())
<div class=”alert alert-danger”>
<button type=”button” class=”close” data-dismiss=”alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

Bootstrap Alert Auto Close Put Bottom

alert message also timer of 2 sec = 2000

<script>
$(document).ready(function() {
// show the alert
setTimeout(function() {
$(“.alert”).alert(‘close’);
}, 2000);
});
</script>

public function update(Request $request, $id)
{
$this->validate($request, [
‘name’ => ‘required’,
‘permission’ => ‘required’,
]);

Example Success Message

$role = Role::find($id);
$role->name = $request->input(‘name’);
$role->save();

$role->syncPermissions($request->input(‘permission’));

return redirect()->route(‘roles.index’)
->with(‘success’,’Role updated successfully’);
}

Using ->with Can Message all type and Custom

Github File

Gihub Laravel Starter Project

Blog

http://raviyatechnical.blogspot.com

--

--

--

RAJ Technologies Pvt. Ltd. an entity promoted by well-qualified engineers, computer professionals and businessmen who bring with them several years of business and professional experience

Recommended from Medium

Is your software ready for localization?

Paste Values Only

Don’t Brick the Userbase

Setting Up iOS Development Environment

Running Postgres On Kubernetes: A Quick Guide

Juicy Fog in Unity: A Mini Case Study

Ziktalk App Update Complete: The First Step Towards ZIK Adoption

Ziktalk to Participate in Luniverse Partner’s Day

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bhargav Raviya

Bhargav Raviya

I am Laravel, Flutter, and Digital Marketing Expert and follow the blog on raviyatechnical.blogspot.com Github:-https://github.com/bhargavraviya

More from Medium

Laravel Livewire Crud Tutorial

How to Install JWT Auth in Laravel Project

Removing all Vue dependencies from Laravel in 4 steps

Laravel create an admin panel from scratch — Part 1— Installation