[Vuejs]-405 (Method Not Allowed) – Laravel and Vue.Js

0👍

As user Mihai pointed out, you need to chain your POST request after a get request to csrf.

Here’s how it looks like with Laravel Sanctum:

import axios from 'axios'

const baseUrl = 'http://yourdomain.com'
const api = axios.create({
  baseURL: baseUrl,
  withCredentials: true
})
const payload = {}

api().get('/sanctum/csrf-cookie').then(() => {
  return api().post('api/like', payload).then(resp => {
     // Do stuff with resp
  })
})

Leave a comment