My application is a simple CRUD application. I have a delete controller action which redirects back to the list when the item is successfully deleted. What I'm trying to add now is a message to the user that the data was successfully deleted.
My Controller Action:
public function deleteItem($id)
{
    try {
        $item = Item::findOrFail($id);
        $item->delete();
        return Redirect::to('list')->with('message', 'Successfully deleted');
    } catch (ModelNotFoundException $e) {
        return View::make('errors.missing');
    }
}
The part of my list.blade.php view where I try to display the message:
@if (isset($message))
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        {{ $message }}
    </div>
@endif
The problem that I have is that the $message variable is always empty ..
You can use this on your blade template:
@if( Session::has('message') )
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        {{ Session::get('message') }}
    </div>
@endif
Reference: easylaravelblog
Since the with method flashes data to the session, you may retrieve the data using the typical Session::get method.
So you have to get as
$message = Session::get('message');
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With