How to use bootstrapping with a custom query builder in Laravel

I'm new to Laravel 5.4 and working on some query manipulation. I have now created a query using the query builder 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 tables "dates" and "modules". Each date, as well as a module, belongs to blocks.

Now I want to get all blocks with programs, dates and modules. I know I can use the () method to get all of these. But according to my Laravel knowledge, I can only use the () method if I have a model file of each table and I have a relationship between them.

But you don't want to use the model and define the relationship between them. I just want to know How can I get block data with programs, dates and modules without creating a model and defining relationships between them in the model? Is there any other way to use the () method without a model?

Block dates and modules are conditional, Sometimes I don't need the data of this block table.

Please help me with this.

+3


source to share


1 answer


You cannot do this automatically. Junk loading is only for the Eloquent model, so you cannot use it with the query builder. However, in most cases, you can use Eloquent for more complex queries as well (you can also use joins when using Eloquent) so that you can use eager loading.



But if you don't want to use Eloquent at all, obviously you will need to create some custom mechanism for active loading.

+1


source







All Articles