javascript - Uncaught (in promise) 500 (Internal Server Error) BadMethodCallException -


i use vue 2.0 , laravel 5.4

i trying build matching system

that has dynamic vue component in (i.e when likes person tells you have liked person and/or when accepting tells you're match)

but component keeps loading, , in dev-tools tells me has internal server error(500) (+ uncaught (in promise))

and in network shows badmethodcallexception--> call undefined method illuminate\database\query\builder::matches_with()

i'v included component in app.js file (resources)-->> vue.component('match', require('./components/match.vue'));

my vue file

<template>     <div>         <p class="text-center" v-if="loading">              loading...         </p>        <p class="text-center" v-if="!loading">               <a v-if="status == 0" @click="like_user">               <span title="i you" class="send-heart"></span>             </a>     <a href=""><span title="i to" class="pending" v-if="status ==    'pending'" @click="mutual_like">accept</span></a>           <a href="">             <span title="you person" class="pending" v-        if="status == 'waiting'"></span>         </a>               <span v-if="status == 'match'" title="chat" class="chat"></span>         </a>      </p> </div> </template>   <script> export default { mounted() {     this.$http.get('/check_match_status/' + this.profile_user_id)         .then((resp) => {             console.log(resp)             this.status = resp.body.status             this.loading = false         })   },   props: ['profile_user_id'],   data() {     return {         status: '',         loading: true     } }, methods: {     like_user() {         this.loading = true         this.$http.get('/like_user/' + this.profile_user_id)             .then((r) => {                 if (r.body == 1)                     this.status = 'waiting'                  this.loading = false             })      },     mutual_like() {         this.loading = true         this.$http.get('/mutual_like/' + this.profile_user_id)             .then((r) => {                 if (r.body == 1)                     this.status = 'match'                  this.loading = false             })         }       }    }  </script> 

my controller

<?php  namespace app\http\controllers;  use illuminate\http\request; use auth; use app\profile; use illuminate\support\facades\event; use app\user; use app\matches; use app\traits\matchable; use db;   class matchescontroller extends controller  {   use matchable;    public function check($id){                  if (auth::user()->matches_with($id) === 1)                   {                     return [ "status" => "match" ];                 }                   if(auth::user()->has_pending_like_request_from($id))                      {                 return [ "status" => "pending" ];                          }                           if(auth::user()->has_pending_like_request_sent_to($id))                      {                 return [ "status" => "waiting" ];                          }        return [ "status" => 0 ]; }        public function like_user($id) {      //notify users     return auth::user()->like_user($id);  } public function mutual_like($id) {     //sending nots    return auth::user()->mutual_like($id);   }  public function matches() {     $uid = auth::user()->id;     $match1 = db::table('matches')             ->leftjoin('users', 'users.id', 'matches.recipient_id') // not loggedin send request             ->where('status', 1)             ->where('sender_id', $uid) // loggedin             ->get();     //dd($friends1);     $match2 = db::table('matches')             ->leftjoin('users', 'users.id', 'matches.sender_id')             ->where('status', 1)             ->where('recipient_id', $uid)             ->get();     $matches = array_merge($match1->toarray(), $match2->toarray());     return view('matches', compact('matches'));    }       } 

my trait

use app\matches;  trait matchable {  public function like_user($recipient_id) {        if($this->id === $recipient_id)     {         return 0;     }     if($this->matches_with($recipient_id) === 1)     {         return "you match!";     }     if($this->has_pending_like_request_sent_to($recipient_id) === 1)     {         return "you liked person.";     }     if($this->has_pending_like_request_from($recipient_id) === 1)     {         return $this->like_user($recipient_id);     }     $match = matches::create([         'sender_id' => $this->id,         'recipient_id' => $recipient_id     ]);     if($match)     {         return 1;     }     return 0;           }  public function mutual_like($sender_id) {     if($this->has_pending_like_request_from($sender_id) === 0)     {         return 0;     }     $match = matches::where('sender_id', $sender_id)                     ->where('recipient_id', $this->id)                     ->first();     if($match)     {         $match->update([             'status' => 1         ]);         return 1;     }     return 0; }   public function matches() {        $matches = array();      $m1 = matches::where('status', 1)                 ->where('sender_id', $this->id)                 ->get();     foreach($f1 $match):         array_push($matches, \app\user::find($match->recipient_id));     endforeach;     $matches2 = array();      $m2 = matches::where('status', 1)                 ->where('recipient_id', $this->id)                 ->get();     foreach($m2 $match):         array_push($match2, \app\user::find($match->sender_id));     endforeach;     return array_merge($matches, $match2);  }  public function pending_like_requests() {     $users = array();      $matches = matches::where('status', 0)                 ->where('recipient_id', $this->id)                 ->get();     foreach($matches $match):         array_push($users, \app\user::find($match->sender_id));     endforeach;      return $users; }      public function matches_ids() {     return collect($this->matches())->pluck('id')->toarray(); }  public function matches_with($user_id) {     if(in_array($user_id, $this->matches_ids()))     {         return 1;     }     else     {         return 0;     } }  public function pending_like_requests_ids() {     return collect($this->pending_like_requests())->pluck('id')->toarray(); }      public function pending_like_requests_sent() {     $users = array();     $matches = matches::where('status', 0)                     ->where('sender_id', $this->id)                     ->get();     foreach($matches $match):         array_push($users, \app\user::find($match->recipient_id));     endforeach;     return $users; }   public function pending_like_requests_sent_ids() {     return collect($this->pending_like_requests_sent())->pluck('id')- >toarray(); }   public function has_pending_like_request_from($user_id) {     if(in_array($user_id, $this->pending_like_requests_ids()))     {         return 1;     }     else     {         return 0;     } } public function has_pending_like_request_sent_to($user_id) {     if(in_array($user_id, $this->pending_like_requests_sent_ids()))     {         return 1;     }     else     {         return 0;         }     }     } 

my model

namespace app;  use illuminate\database\eloquent\model;  class matches extends model {   protected $fillable = ['sender_id', 'recipient_id', 'status',]; } 

move matchable trait user model not matchescontroller controller

<?php  namespace app;  use illuminate\foundation\auth\user authenticatable; use app\matches\matchable;  class user extends authenticatable {     use matchable; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -