Create and Display Flash Message

PHOTO EMBED

Fri May 14 2021 23:46:32 GMT+0000 (UTC)

Saved by @slendabilt

/**
* Controller Code
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|unique:categories'
]);

$category = new Category();

Category::create([
'name' => $request->name
]);

// create flash message to show success
// 
session()->flash('success', 'Category Successfully Created');

return redirect(route('categories.index'));
}

/**
* View Code
*/
<div class="container">
// if session has success message, display it
  @if (session()->has('success'))
    <div class="alert alert-success">
    	{{ session()->get('success') }}
    </div>
  @endif
</div>
content_copyCOPY

https://laravel.com/docs/8.x/responses#redirecting-with-flashed-session-data