A
A
akdes2018-05-08 12:47:26
Laravel
akdes, 2018-05-08 12:47:26

Why doesn't "using('CustomPivot')" work in Laravel 5.6 model?

Hi all.
I want to link the Location model and Locationgroups (n:m) using the custom Pivot-Model LocationgroupLocation
Locationgroup-Model:

class Locationgroup extends Model
{
    public function locations()
    {
        return $this->belongsToMany('App\Location\Models\Location')->using('App\Location\Models\LocationgroupLocation');
    }
}

Pivot LocationgroupLocation
class LocationgroupLocation extends Pivot
{
    protected $table = 'locationgroup_location';

    public function location()
    {
        return $this->hasMany('App\Location\Models\Location');
    }

    public function locationgroup()
    {
        return $this->hasMany('App\Location\Models\Locationgroup');
    }
}

When called: an error occurs:
$locationgroup->load('locations');
QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dev.location_locationgroup' doesn't exist

If you comment out the using(..) call in the "locations" link, the error remains the same. Those. Laravel, despite the use of using, tries to load the standard connection, according to its naming conventions.
Tell me what is my mistake?
Thank you very much!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question