The error i am getting is "Call to undefined function App\belongsToMany".
This is one of the two models that is used for the relationship:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Review extends Model
{
protected $table = "reviews";
protected $fillable = [ 'user_id','email','review'];
public function user()
{
return $this->belongsTo('App\User');
}
public function votes()
{
return $this->belongsToMany('App\User')->withPivot('vote')->withTimestamps();
}
public function categories()
{
return $this-belongsToMany('Category','category_review','review_id','category_id')->withTimestamps();
}
public function tags()
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
}
My other model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
public function reviews()
{
return $this->belongsToMany('App\Review','category_review','category_id','review_id')->withTimestamps();
}
public function children()
{
return $this->hasMany('App\Category','parent_id');
}
public function parent()
{
return $this->belongsTo('App\Category','parent_id');
}
}
The problem is, i can run the App\Category::find(1)->reviews; but, i can't run App\Review::find(1)->categories; It says "Call to undefined function App\BelongsToMany"
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TezCfu
via IFTTT
Aucun commentaire:
Enregistrer un commentaire