Biswas Sampad
Biswas Sampad

Reputation: 451

status: 405, statusText: "Method Not Allowed", in axios .post laravel

i am trying to do axios.post method for sending the messages . But i am getting this error repeatedly.

my script looks like this

sendMsg(){
            if(this.msgFrom){
               axios.post('messages/sendMessage/',{
                   conID:this.conID,
                   msg:this.msgFrom
               })
                   .then(response => {
                       console.log('saved successfully');

                   })
                   .catch(function (error) {
                       console.log(error.response);
                   });
            }
        }

Route looks like this

Route::post('/messages/sendMessage','Messages@sendmsg');

and controller looks like this

public function sendmsg(Request $request){
        echo $request->msg;
   }

and i am getting the error code 405,method not allowed , any solutions please.

Upvotes: 4

Views: 6223

Answers (1)

aturingmachine
aturingmachine

Reputation: 165

I am going to make an assumption:

  • Your route is currently in the default api.php file

So you may need to modify your URL in the axios request to include the /api/:

/api/messages/sendMessage

Upvotes: 1

Related Questions