Hi @thibaultvanc,
Thanks for your answer. I've created this test, but I'm still having a problem: BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::attach does not exist.
/** @test */
public function a_tag_has_posts()
{
$this->withoutExceptionHandling();
$tag = factory('App\Tag')->create();
$post = factory('App\Post')->create();
$this->assertCount(0, $tag->posts);
$tag->posts->attach($post);
$this->assertCount(1, $tag->fresh()->posts);
$this->assertTrue($tag->posts()->first()->is($post));
}
I don't have an attach-method on my Tag model, but I do have this relationship:
public function posts()
{
return $this->belongsToMany(Post::class, 'posts_tags');
}
So, do I have to make an attach function or should it be working?
Thank you! Jeroen