MoeSaid
4 months ago

Storing Issue

Posted 4 months ago by MoeSaid

Hi mates, am facing a weird issue will store some data to the Db using axios

the issue is , when i push the data to the controller works without any issues once am trying to save it always return with err

Request failed with status code 500

here's my form

 <form >
        @csrf
        <textarea v-on:click="clear" v-on:keydown.enter="submit" class="form-control" v-model="msg" rows="8"></textarea>

        <button v-on:click="submit" class="btn btn-dark" type="button" name="button">
          <i class="fa fa-paper-plane"></i>
        </button>

      </form>

the vue component

var chat = new Vue({

          el: '#chat',

          data: {
              msg: 'Type New Message...',
              room: '{{$room->id}}',
              user: '{{auth()->user()->id}}',
              avatar: '{{auth()->user()->image}}',
          },

          methods: {

              clear: function (e) {
                    e.preventDefault();
                    this.msg = '';
              },

              submit : function (e) {
                  e.preventDefault();

                  axios.post('api/chat/add' , {
                      room:     this.room,
                      user:     this.user,
                      avatar:   this.avatar,
                      body:     this.msg

                  }).then(function (res) {

                      console.log(res.data);
                      // this.$emit('new' , res.data);

                  }).catch(function (err) {
                      console.log(err.message);
                  });

                  this.msg = '';
              }
          }

      });

my controller

public function new(Request $req)
    {
        $msg = new GroupChat;
        $msg->room_id = $req->room;
        $msg->user_id = $req->user;
        $msg->avatar  = $req->avatar;
        $msg->body    = $req->body;

        $msg->save();

        return response()->json($req);
    }

what am missing guys? appreciate any help.

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