Ad

Laravel 5 Pass And Get A Flash Data Not Working

- 1 answer

i want to pass a flash data from store function to add function but i cant get it to work, i always get null;

here is my controller

public function add()
{
    return view('cars.add');
}

public function store(CarFormRequest $request)
{
    $car = new Cars(array(
        'name' => $request->get('name'),
        'color_id' => $request->get('color')
    ));

    $car->save();
    $car->position_id = $car->id;
    $car->save();

    return redirect('/cars/add')->with('status', 'A Car has been added');
}

here is my view:

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif
Ad

Answer

Add in your controller

session()->flash('status', 'Task was successful!');

and in View:

@if (session->has('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif
Ad
source: stackoverflow.com
Ad