0

I set up a controller to pass errors if validation fails and another message if passed it.

if ($v->fails()) {
    return redirect('tickets/create')->withInput()->withErrors($v->errors());
} else {
    $ticket_id = $this->salvataggio($request);
    
    return redirect('tickets/' . $ticket_id . '/edit')
        ->with(['status' => 'success']);
}

In the blade file of the view, I can read the error variable but I can't read the status.

@if(Session::has('status'))
   <div class="alert alert-success">{{Session::get('status')}}</div>
@endif

I have read and tried many methods to retrieve Session but it seems doesn't work. I've already used this method on a previous project with Laravel 5 but in this version (8.11.0), has something has changed?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Roberto Remondini
  • 242
  • 1
  • 6
  • 19
  • in what blade file do you have this check to see if you have the session variable named 'status'? – lagbox Oct 28 '20 at 21:04

2 Answers2

1

You have to create the session first...

// Via a request instance...
$request->session()->put('status', 'success');

// Via the global helper...
session(['status' => 'success']);

And then you can retrieve the session data...

// Via a request instance...
$value = $request->session()->get('status');

// Via the global helper...
$value = session(['status']);

// In blade...
{{session('status')}}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
-1

You used the with method so you should change your code like below:

@if($status)
   <div class="alert alert-success">{{$status}}</div>
@endif
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ramin eghbalian
  • 2,348
  • 1
  • 16
  • 36