Unexpected error 500 (Internal Server Error) occurred due to BadMethodCallException

Using Vue 2.0 and Laravel 5.4, I am working on creating a matching system that includes a dynamic Vue component. For example, when someone likes another person, it should immediately show that the like has been sent or if the like is mutual, it should indicate that there is a match.

However, I'm facing an issue where the component keeps loading and in the developer tools, it shows an internal server error (500) along with an Uncaught (in promise) error. Additionally, in the network tab, there is a BadMethodCallException - Call to undefined method Illuminate\Database\Query\Builder::matches_with()

I have included the component in my app.js file as follows: Vue.component('match', require('./components/Match.vue'));

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 like you" class="send-heart"></span>
            </a>
    <a href=""><span title="I like you too" class="pending" v-if="status == 'pending'" @click="mutual_like">accept</span></a>


        <a href="">
            <span title="You like this 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>

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 ];
}

...

}

Trait:

use App\Matches;

trait Matchable {

public function like_user($recipient_id)
{   
    // Logic for liking a user
} 

public function mutual_like($sender_id)
{
    // Logic for mutual liking between users
} 

...

}

Model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Matches extends Model
{
  protected $fillable = ['sender_id', 'recipient_id', 'status',];
}

Answer №1

Relocate the Matchable Trait to your User Model instead of in your MatchesController

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Matches\Matchable;

class User extends Authenticatable
{
    use Matchable;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mass-generated bit.ly maker

Is there a way to efficiently shorten 1200 links at once using the bit.ly API? I have been attempting to create a bulk bit.ly shortener that can read a list of links from a txt file and output the shortened versions. However, I'm facing difficulties ...

The Ionic tab is already finished displaying even before the data has completed loading

Creating a favorites section for a vouchers app has proven to be slightly challenging. When attempting to retrieve the current user's favorite vouchers and display them using ngFor in the HTML, I encountered an issue. The very first time I open the fa ...

When the number of selected students exceeds zero, activate the collapsing feature in React

When the number of students exceeds zero, the collapse should automatically open and the text in Typography (viewStudentList) will display 'Close'. On the other hand, if the student count is zero, the collapse should be closed and the text on Typ ...

Is it necessary to employ JQuery for populating my second drop down menu when the values match those of the first drop down menu?

Currently, I am working on implementing two drop-down menus that will function as time intervals. The objective is to have the second menu populate with values greater than or equal to the selection made in the first menu when a user chooses a year. Below ...

Troubleshooting a problem with a personalized webkit scrollbar in Chrome

Using the CSS property scroll-snap-type: y mandatory; to customize my scrollbar with the following styles: ::-webkit-scrollbar { width: 12px; background: transparent; } ::-webkit-scrollbar-track { background-color: rgba(0, 0, 0, 0.5); -webkit-box-s ...

What is the best way to draw a rectangle outline in Vue.js without the need for any additional packages?

I have been attempting to craft a rectangle outline using vueJS, but so far I have not had much success. I am hoping to achieve this using only CSS, but despite my efforts, I have not been able to find a solution. My goal is to create something similar to ...

PHP code pulling blank data from Unity database

When working with PHP code, I am retrieving names and high scores: if(isset($_REQUEST['command']) && $_REQUEST['getData']!="") { $fetchData=$db->query ("select * from topdowngame"); //this is my database name if ($fetchData->rowC ...

Generating HTML table rows dynamically in Angular based on the number of items stored in a $scope variable

In my current project, I am utilizing Angular to dynamically populate data in an HTML table. Instead of manually coding each row for display, I am in need of a solution that allows me to programmatically define each HTML row. The Angular controller snippet ...

Move to the following array when clicking PHP (using Ajax, perhaps?)

How can I trigger php code when a button is clicked? (I understand the distinction between client-side and server-side. However, I believe I have encountered a similar scenario before.) Consider the following array : $test_id = [ 1 => '15 ...

What is the best location to manage errors within a sequelize ORM query?

I am working with the Sequelize ORM within a Node/Express environment. My database has two tables: one for Users and another for Items. The Item table includes a foreign key that is linked to the UserId in the User table. Whenever I attempt to create an ...

Refining a list according to specific criteria

The challenge Upon login, users are presented with a list of tasks they need to complete. I am looking for a way to filter these tasks based on assignment. The key fields in the table include: **tasks table** task_id | (Foreign Key int) user | (Foreign ...

Dynamic image loading in React with custom properties

I'm facing an issue while trying to display an image using the source stored in this.props.src. The correct name of the image file I want to load, "koolImg", is being output by this.props.src. I have imported the file using: import koolImg from ' ...

Issue with displaying dropdown options retrieved from the database in the Laravel Master blade template on various other pages

I have successfully implemented a menu in my Laravel master blade template and extended it to other pages. The menu has a dropdown feature with options retrieved from the database. However, while it functions correctly on the master template, the same drop ...

How can I successfully use the Confluence REST API to publish a dynamically generated HTML table (created with PHP) without encountering the problematic HTTP

I am striving to build a page within a Confluence wiki that contains a table created using the provided REST API, which can be conveniently edited by wiki users using the WYSIWYG editor once the page is established. To achieve this, I have organized vario ...

Choosing values from a variety of select option boxes using jQuery

I'm experiencing an issue with selecting values in a multiple select option box. Despite my efforts, I haven't been able to get all the desired items selected at once. Currently, when I run the code below, only the first option is being selected ...

I encounter internal server errors when trying to upload images in React

Attempting to send a post request with an image, but encountering errors without understanding why. const [image, setImage] = useState([]); const handleImage = (event) => { setImage(...Array(event.target.files[0])) } const handleSubmit ...

Error: npx is unable to locate the module named 'webpack'

I'm currently experimenting with a customized Webpack setup. I recently came across the suggestion to use npx webpack instead of node ./node_modules/webpack/bin/webpack.js. However, I am encountering some difficulties getting it to function as expecte ...

Guide on invoking an Angular 1.5 component with a button press

Having just started learning Typescript, I'm struggling to figure out how to call my Angular component "summaryReport" on a button click. Here's a snippet of my code: Let's say I have a button that should call my component when clicked with ...

Can anyone provide guidance on implementing pagination with Firebase Realtime Database in Vue.js?

Currently, I am working on implementing pagination for my data from the Firebase Realtime Database. Do I need to switch to Firestore instead? Google's documentation provides detailed information on how to implement pagination using Firestore (https:// ...

Animating elements within Firefox can sometimes cause adjacent elements to shift positions

Currently, I am working on a single-page website that utilizes keyboard-controlled scrolling. To achieve the desired scroll effect, I have developed a JavaScript function that animates divs. Here is the JavaScript code: var current_page = "#first"; func ...