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

TheBlueDragon's avatar

how to redirect to another page after submitting the form

hello iam trying to redirect to another page after submiting the form

in normal html in my controller iam using the following

return redirect()->route('training_schedules.index');

but this not working with vuejs

now in my view i have following

               submitForm: function (e) {
                    console.log(this.$data);
                    axios.post(this.baseUrl, this.$data).then(function (response) {
                        console.log(response);
                    });
                    this.submitted = true;
                },

so i want to redirect to the same route('training_schedules.index') if my response is ok

how i can do that

0 likes
4 replies
rickbolton's avatar
Level 8

In your controller you could return a json response instead like..

return ['redirect' => route('training_schedules.index')];

then

 axios.post(this.baseUrl, this.$data).then(function (response) {
    window.location = response.data.redirect;
});
15 likes
TheBlueDragon's avatar

its does the work

i need to make more if statements and checking if i got an error as for now i dont have so its redirect me on undefined page if my controller return an error

thanks again

richtone's avatar

Hi, I'm trying to get to te bottom of this. Could someone direct my for a reason for this behaviour? What exactly prevents the laravel backend from making the redirect?

Sinnbeck's avatar

That it isn't returning an actual redirect but just an array where the key happens to be named redirect

return ['redirect' => route('training_schedules.index')]; //this is just an array

Please or to participate in this conversation.