0👍
replace it with return ‘ok’ ;. console.log() is javascript, it doesn’t work in php – porloscerros Ψ Nov 28 at 23:37
0👍
It looks like you have the wrong midleware
auth instead auth:api in your controllers constructor
see: https://laravel.com/docs/5.8/api-authentication#protecting-routes
You also probably miss some headers in your axios calls, you could verify in
your browser if they are all there.
Also verify your DOM for the csrf-token
Then you could use a wrapper Axios object to set your default headers.
like this. (Save it for example to api.js)
import Axios from 'axios'
export default() => {
return Axios.create({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN' : document.head.querySelector('meta[name="csrf-token"]').content
}
})
}
Then import the axios your vue component..
import Api from './api';
And you can use it then like an axios object
Api().request()
Or if you will use this single way of authentication through all your axios calls. You just do it the same way as laravel starts out in their bootstrap file
Like this:
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';