Laravel-Test-Helpers icon indicating copy to clipboard operation
Laravel-Test-Helpers copied to clipboard

->withPivot() makes assertBelongsToMany() fail

Open martindilling opened this issue 11 years ago • 2 comments

I'm trying to write a test for this

public function challengeoptions()
{
    return $this->belongsToMany('Challengeoptions')
                ->withPivot('donepct')
                ->withTimestamps();
}

But when trying to use assertBelongsToMany() I'm just getting the error:

PHP Fatal error:  Call to a member function withPivot() on a non-object in....

Anyone know a way to fix it, or to test it another way? :)

martindilling avatar Aug 07 '13 00:08 martindilling

I get the same error because my relationships are something like this:

public function midias()
{
    return $this->hasMany('Midia', 'id_conteudo')
        ->where('model', '=', 'Blog')
        ->orderBy('ordem', 'ASC');
}

Fuhrmann avatar Sep 04 '13 20:09 Fuhrmann

Just added pull request #52 that fixes this. :)

SammyK avatar Jan 08 '14 22:01 SammyK