mardi 2 mai 2017

How to use eager loading with custom query builder in Laravel

I am new to Laravel 5.4 and working on some query manipulation. Now I have created an query using query builder which is shown below:

$view = DB::table('blocks')
    ->leftjoin('programmes', 'blocks.programme_id', '=', 'programmes.id')
    ->select('blocks.id', 'blocks.programme_id', 'blocks.name', 'blocks.colour', 'blocks.year', 'programmes.title AS programme');  

I have two more table "dates" and "modules". Each dates as well as module belongs to blocks.

Now I want to fetch all blocks with programmes, dates and modules. I know i can use with() method to get all of these. But as per my knowledge on Laravel, I can use with() method only if I have model file of each table and have relationship between them.

But do not want to use model and define relationship between them. I just want to know How can I get block data with programmes, dates and modules without creating model and defining relationship betwen them in model? Is there any other way to use with() method without model?

Block dates and modules are conditional, Sometime I dont want get data of this table with block.

Please help me on this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire