Plural level hasManyThrough relationships with Eloquent

I use EloquentPHP in my application and struggle with attitude hasManyThrough.

Here is my structure:

Company 
   id
   name

Admin
   id
   company_id
   name

Offer
   id
   admin_id
   name

Application
   id
   offer_id
   candidat_id

Everyone Adminis a part Companyand can send messages Offer, and candidates can do Applicationin this proposal.

I am trying to retrieve all the applications that were made in offers that were launched by the administrators of this company.

I tried using relationships hasManyThroughin my model Company, for example:

public function applications()
{
    return $this->hasManyThrough("Application", "Offer");
}

but I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'offers.entreprise_id' in 'field list' (SQL: select `applications`.*, `offers`.`entreprise_id` from `applications` inner join `offers` on `offers`.`id` = `applications`.`offer_id` where `offers`.`entreprise_id` in (1))

This makes sense because he thinks it Offeris listed in Company, not in Admin.

, Admin , , , ?

, , , , Eloquent , . , ?

+4

Source: https://habr.com/ru/post/1599165/


All Articles