Relationship in relationsip in relationship with limit

Posted 1 year ago by arctushar

Hi I have a table name and column name given below

  1. sectors = 'id' , 'name'
  2. codelists = 'id' , 'name' , 'sector_id'
  3. datas = 'id', 'codelist_id' , 'trade', 'volume'

In Codelist Model I have 'datas' method

    public function datas()
        return $this->hasMany('App\Data');

in Sector Model I have method

    public function codelists()
        return $this->hasMany('App\Codelist');

Now I want to make a query which will give me

  1. Last 03 Sector name
  2. Correspondence Every sector last 04 codelist
  3. then corresondence every codelist last 05 datas

Is it possible ?? I tried by below

        return $sectors=Sector::select('id','name')->with(array('codelists'=>function($query){

Here I found that only for first codelist of first first sector, 05 datas is showing. All other is null array for datas.

can anybody give me solution ?

Please sign in or create an account to participate in this conversation.