alphadev
4 months ago
264
8
Laravel

Problem with axios POST

Posted 4 months ago by alphadev

hi m trying to save data in db using axios in vue.js but it gives this error:

  app.js:285 POST http://127.0.0.1:8000/api/task 500 (Internal Server Error)
 
  app.js:651 Uncaught (in promise) Error: Request failed with status code 500
    at createError (app.js:651)
    at settle (app.js:814)
    at XMLHttpRequest.handleLoad (app.js:184)

code:

  <script>
    export default {

     data(){
       return{
          title: ''
        }
      },

     mounted() {
         console.log('Component mounted.')
     },

     methods:{
         addTask(){
            axios.post('./api/task',{title:this.title});
            alert('Adding Task');
          }
      }
   }
  </script>

controller:

  public function store(Request $request)
  {
      Task::create($request->all());

      return (['message' => 'task was successful']);
   }

Please sign in or create an account to participate in this conversation.