I have a vuejs component that acts as my login form and I am trying to passing in the form through a Laravel controller similar to how you would do it in blade.php <from method="POST" action="login"> and in web.php Route::post('/login', 'LoginController@login').
Where LoginController should simply redirect to a new view (testing):
class LoginController extends Controller {
public function login() {
return view( 'home' )
}
}
The issue is that while the form does get submitted and gets passed in the controller, the entire home.blade.php html gets loaded back as response data and not as a new 'home.blade.php' view.
Here is the vuejs login component:
<template>
<div id="form-input">
<form method="POST" @submit.prevent="login" :class="{ 'disable-interaction' : submitted }">
<input class="single-line-input" placeholder="Email" type="text" name="email" v-model="form.email">
<input class="single-line-input space" placeholder="Password" type="password" name="password" v-model="form.password">
<div class="large bottom">
<p v-if="error" class="error large">{{ error }}</p>
<button class="large btn-important" type="submit">sign in</button>
<a class="large btn-important-inverted" href="register">register</a>
<a class="simple-link center" v-bind:href="back">back</a>
</div>
</form>
</div>
</template>
<script>
export default {
props: {
error: String,
back: String
},
data: function() {
return {
submitted: false,
form: {
email: '',
password: ''
}
}
},
methods: {
login: function() {
this.submitted = true;
axios.post('login', this.form)
.then(res => console.log(this.form))
.catch(err => console.log(err));
this.submitted = false;
}
}
}
</script>
Which I simply call in login.blade.php:
@extends('layouts.auth')
@section('form')
<login-form
error="{{ isset($error) }}"
back="{{ url('home') }}"
></login-form>
@endsection
And in my web.php:
Route::get('/login', function () { return view('auth.login'); });
Route::post('/login', 'LoginController@login');