I'm using Laravel 5, and I'm a bit new to this framework. I searched a lot for the problem, but in return I got nothing related.
So, I have two models: Article and Tag.
In Article Model I have a method like this:
public function tags() {
return $this->belongsToMany("App\Tag");
}
And in my Tag Model I have a method like this:
public function articles() {
return $this->belongsToMany("App\Article");
}
Now the thing is that when I'm testing this in tinker like this:
$article->tags()->attach(1);
It gives me the following Exception:
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::tags()'
But when I'm calling it like this:
$tag->articles()->attach(1);
It totally works like a charm and It doesn't throw any kind of Exception whatsoever.
I'm actually learning this stuff from Laracast and my Classes and methods and files are kind of like this: BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::belongToMany()'
Except I think I don't have a typo problem.