Laravel Tutorials
- What is laravel
- Laravel Installation
- Directory Structure
- htaccess
- Remove public from url
- Artisan Command
- Laravel Configuration
- Routing Configuration
- Namespaces
- Request
- Response
- Controller
- Model
- User Authentication
- Multi User Authentication
- Database Seeding
- Database
- Database Query
- ORM
- One-to-One Relationship
- One-to-Many Relationship
- Many to Many Eloquent Relationship
- Has One Through
- Has Many Through
- Querying Relations
- Middleware
- Laravel Views
- Blade Views
- Print data on view page
- Get Site URL
- Get URL Segment
- Get images from Storage folder
- Clear cache
- Form Class not found
- Flash Message in laravel
- Redirections
- path
- CRUD Projerct
- CRUD in Laravel
- CRUD progran
- Laravel Validation
- Jquery Validation
- Cookie
- Session
- Email Send in laravel
- File uploading
- CSRF Protection
- Helper in Laravel
- Helper Functions
- Guzzle Http Client
- Paypal Payment Gatway Integration
- Cron Job in laravel
- Flash message
- path
- Errors Handling
- Date Format
- Date Format Validation
- Display Image on View Page
- Update User Status using toggle button
- Delete Multiple Records using Checkbox in Laravel?
- Confirmation Before Delete Record
- Delete image from storage
- Remove/Trim Empty & Whitespace From Input Requests
- Block IP Addresses from Accessing Website
- How to Disable New User Registration in Laravel
- Redirect HTTP To HTTPS Using Laravel Middleware
- CKEditor
- slug generate unique
- Prevent Browser's Back Button After Logout
- Datatable dunamically
- encrypt & Decript
- Download File
- Rest API
- Shopping Cart
- Shopping Cart Example
- Dynamic Category-Subcategory Menu
- Ajax Search
- Interview Question
- laravel Tutorilal link
- laravel Tutorilal
Important Links
Flash message in Laravel?
we will create new blade file flash-message.blade.php. In this file we will write code of bootstrap alert and check which messages come.
Step 1: Create Global File For Flash Message
File name : resources/views/flash-message.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>
Please check the form below for errors
</div>
@endif
Step 2: Use Flash Message in Theme
include flash-message.blade.php file in your theme default file.
@include('flash-message')
File name : resources/views/layouts/app.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Styles -->
<link href="/css/app.css" rel="stylesheet">
</head>
<body>
<div id="app">
@include('flash-message')
@yield('content')
</div>
<!-- Scripts -->
<script src="/js/app.js"></script>
</body>
</html>
Step 3: Use Flash Messages with Redirect
1. Redirect with success message
public function create(Request $request)
{
$this->validate($request,[
'title' => 'required',
'details' => 'required'
]);
$items = Item::create($request->all());
return back()->with('success','Item created successfully!');
}
Redirect with error message
public function create(Request $request)
{
return redirect()->route('home')
->with('error','You have no permission for this page!');
}
Redirect with warning message
public function create(Request $request)
{
return redirect()->route('home')
->with('warning',"Don't Open this link");
}
Redirect with info message
public function create(Request $request)
{
$this->validate($request,[
'title' => 'required',
'details' => 'required'
]);
$items = Item::create($request->all());
return back()->with('info','You added new items, follow next step!');
}
Validation Error
public function create(Request $request)
{
$this->validate($request,[
'title' => 'required',
'details' => 'required'
]);
.....
}
Add Method in your Controller
return redirect()->with('message', 'Welcome Sana in this world!');
Add your Blade File
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
Error Alert Message in laravel
Controller Class :-
return back()->with('error', 'Sorry Sana!');
or return redirect error message.
return redirect()->with('error', 'Sorry Sana!');
Blade File :-
@if(session()->has('error'))
<div class="alert alert-danger">
{{ session()->get('error') }}
</div>
@endif
You can sent session messages from your controller:
Blade File :-
return redirect()->with('info', 'The info message!');
return redirect()->with('danger', 'The dangermessage!');
return redirect()->with('warning', 'The warningmessage!');