Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

makapaka's avatar

Can you do redirect with flash in Spark?

This doesn't seem to work in laravel spark return redirect($this->redirectPath('/login')->withError('try again')); neither does the version with withSuccess.

I've noticed there is something like Spark::afterLoginRedirectTo('login') but not sure how to use flash message or what would be the better way to pass through some data for the view to display like this?

0 likes
1 reply
Pixellius's avatar

from what little i know you can try this.

Make sure your login route is set in the web.php, if you are using php artisan make:auth you are pretty much covered.

So in your controller you do this:

Session::flash( 'error' , 'try again' );
return redirect()->route('login');

Then to display the messages in the related view you do this:

@if(Session::has('error'))

  <div>
    <strong>Error:</strong> {{Session::get('error')}}
  </div>

@endif

Please or to participate in this conversation.