How to redirect through anchor element to a route with session message Hey everyone!
I want to somehow represent this:
redirect()->route('user.dashboard')->with('section', 'bank');
inside the href attr of an anchor element
<a href="{{ route('user.dashboard') }}"></a>
but I'm not really sure it can happen the way I think. I could also use javascript for the redirection but I cannot find a way to set Laravel session message inside that redirection. Any ideas how to make this work?
maybe this can help !
return redirect()->route('user.dashboard')->withFragment('myfragment')->with('section', 'bank');
in blade
<div id="myfragment"> hi there </div>
@CODE -AXION I'm not really sure you understand what I'm trying to achieve.
@Laralex
return redirect()->route('your route')
->with('message',"Your message. <a href='{ url('/posts') }'>Click here</a>
->with('status', 'success');
@laralex you could use a query param instead:
<a href="{{ route('user.dashboard', ['section' => 'bank']) }}"></a>
Then in the Controller action; you can get the section either from the Session or from the Request:
$section = session('section', request()->get('section'));
@tykus That's not a solution for me. Any other ideas? Thanks for your time tho.
@Laralex in that case, what you are attempting is not possible unless the Session already has the section key before the view with that link is rendered.
So link to a route where you then return this redirect()->route('user.dashboard')->with('section', 'bank');
@Sinnbeck Yeah, but this costs me a declaration of a whole route just for a redirection which I don't think is the best option.
@Laralex what problem are you actually trying to solve here?
Please sign in or create an account to participate in this conversation.