#In Controller
use Session;
Session::flash('message', "Special message goes here");
return Redirect::back();
#In View
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif
//If it didn't help (still, keep routes.php without web middleware), you can try little bit different approach:
return redirect()->back()->with('message', 'IT WORKS!');
// Displaying message if it exists:
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
return redirect()->route('agent')->with(
'success', __('Agent successfully added!')
);
return redirect()->back()->with('error', __('Permission Denied.'));
create validation errors
<!-- /resources/views/post/create.blade.php -->
<h1>Create Post</h1>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- Create Post Form -->
##error message:
<!-- /resources/views/post/create.blade.php -->
<label for="title">Post Title</label>
<input id="title" type="text" name="title" class="@error('title') is-invalid @enderror">
@error('title')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
...
$recipe->save();
$data = [
'success' => true,
'message'=> 'Your AJAX processed correctly'
] ;
return response()->json($data);