Я использую vue 2.0 и Laravel 5.4
Я пытаюсь построить систему соответствия
в нем есть динамический компонент vue (то есть, когда кому-то нравится другой человек, он сразу же сообщает вам, что вам понравился этот человек, и / или, принимая его, сразу же говорит, что вы совпадаете)
но компонент продолжает загружаться, и в моих инструментах разработчика он говорит мне, что имеет внутренняя ошибка сервера (500) (+ Uncaught (в обещании))
и в моей сети это показывает
BadMethodCallException—>
Вызов неопределенного метода Illuminate \ Database \ Query \ Builder :: match_with ()
я включил компонент в мой файл app.js (ресурсы) — >> Vue.component (‘match’, require (‘./ components / Match.vue’));
мой Vue файл
<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 to" 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>
мой контроллер
<?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') // who is not loggedin but send request to
->where('status', 1)
->where('sender_id', $uid) // who is 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'));
}
}
моя черта
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 are already a match!";
}
if($this->has_pending_like_request_sent_to($recipient_id) === 1)
{
return "You already liked this 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 as $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 as $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 as $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 as $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;
}
}}
моя модель
namespace App;
use Illuminate\Database\Eloquent\Model;
class Matches extends Model
{
protected $fillable = ['sender_id', 'recipient_id', 'status',];
}
переехать Matchable
Черта к вашему User
Модель не ваша MatchesController
контроллер
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Matches\Matchable;
class User extends Authenticatable
{
use Matchable;
Других решений пока нет …