-2

I have a problem with showing error messages or session messages in laravel.

Comment the bootstrap cdn, but makes no differences.

have code like this, works correctly, refreshing the view, but not displaying errors:

Controller.php

return redirect()->route('trainers.show',[$trainer])->with('status','Entrenador actualizado correctamente'); 

blade.php

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

Controller.php

$validatedData = $request->validate([ 'name' => 'required|max: 10', 'avatar' => 'required|image', 'slug' => 'required', 'description' => 'required', ]); 

blade.php

@if ($errors->any()) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $message) <li>{{ $message }}</li> @endforeach </ul> </div> @endif 
2
  • 3
    I think this is a duplicated problem. Please refer to: stackoverflow.com/questions/19838978/… Commented Oct 7, 2019 at 19:55
  • if you refresh the page, the flashed session vars are gone at that point, they are only available on the next request from when they are flashed ... unless you mean something else by refreshing the view Commented Oct 7, 2019 at 21:31

1 Answer 1

0

Regarding the session status, you can use \Session::has('status') and \Session::get('status'), like so:

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

And on your errors, you can also use has(), like so:

@if ($errors->has()) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error}}</li> @endforeach </ul> </div> @endif 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.