I am using Laravel 5.4 and Vue.js. I am sending a post request with axios to the server. I am trying to login the user, but I can't. This is my code...
In my vue file
axios.post('/api/login', this.$data)
.then(res => {
console.log(res.data);
})
.catch(error => console.log(error));
In my api.php file
Route::middleware('guest:api')->post('/login', 'AuthController@login');
In my AuthController.php
public function login(Request $request)
{
$this->validate($request, [
'name' => 'required',
'password' => 'required|min:6',
]);
if ( Auth::attempt( ['username' => $request->name, 'password' => $request->password] , true) )
{
return [
'code' => 200,
'message' => 'Authentication Successful!'
];
}
}
This was my code. After posting the ajax request, if credentials are correct, I am getting the success message in the console. But, I can't visit the homepage route which is under a auth middleware
Please help me to solve this problem asap...