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

finchy70's avatar

Sending session message with window.location.href

window.location.href = '/plant_types/'+this.plant.id; How would I set the session variable so the page '/plant_types/'+this.plant.id' displays a flash('message'). In laravel controller I would normally use

Session::flash('success', 'Questions successfully updated!!'); 
return view('plant_types.show');
0 likes
5 replies
finchy70's avatar

Yes but my component posts to laravel and on response redirects to window.location.href = '/plant_types/'+this.plant.id; to ensure the data has been updated.

rawilk's avatar
rawilk
Best Answer
Level 47

couldn't you just send the message to the view from the controller that handles the endpoint /plant_types/{id} ?

finchy70's avatar

Not really explained this very well. I have built the Vue Flash message component in Episode 29 of Lets build a forum with Laravel.

I am redirecting from my component after the response from the back end. This ensures my data is updated before I display it. I want to redirect to '/plant_types/'+this.plant.id and then display a the success message. As I'm redirecting from the component I used

window.location.href = '/plant_types/'+this.plant.id;

If I try to redirect to the page from the laravel controler with no response the axios post fails with a 500 error.

Can I redirect from the vue component with the equivalent of the ->with('flash', 'Updated Questions!!') so my Vue flash component works.

finchy70's avatar

You are right. I over complicated the matter.

Session::flash('flash', 'Updated Successfully!!);

I'd used

Session::flash('success', 'Updated Successfully!!);

and got the Bootstrap messages.

Please or to participate in this conversation.