JeffreyWay / Laravel-Test-Helpers

Easier testing in Laravel.
https://packagist.org/packages/way/laravel-test-helpers
217 stars 40 forks source link

Added support to model helpers for chaining relationship methods #52

Open SammyK opened 10 years ago

SammyK commented 10 years ago

Now we can add ->withPivot() and ->withTimestamps() methods to model relationship methods without errors.

return $this->belongsToMany('User')->withPivot('foo')->withTimestamps();

This fixes issue #30.

pacobony commented 8 years ago

I'm trying to test one similar function but I get the same error:

public function testBelongsToEmployee()
    {
        $this->assertBelongsToMany('employees', Service::class);
    }
public function employees()
    {
        return $this->belongsToMany(
            Employee::class,
            'catalogo_servicios_roles_empleados',
            'id_servicio',
            'id_empleado'
        )->withPivot('id_rol');
    }

_PHP Fatal error: Call to a member function withPivot() on a non-object in /srv/www/vhosts/api.globalsuite/app/Models/Services/Service.php on line 162 _