M
M
Mykola Ivashchuk2017-08-12 11:04:12
Laravel
Mykola Ivashchuk, 2017-08-12 11:04:12

How to work with Repository in Laravel?

I do not quite understand how to work with repositories in Laravel, for example, if I have a request like:

DB::table('trips')
            ->join('routes', 'routes.trip_id', '=', 'trips.id')
            ->join('vehicles', 'trips.vehicle_id', '=', 'vehicles.id')
            ->where('trips.user_id', '=', $id)
            ->get(['trips.id','from', 'to', 'brand', 'model', 'start_at', 'end_at']);

Or if I have all the connections in the models, then it will be enough:
Trip:all();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pantagruel964, 2017-08-12
@mykolaim

If there are connections, then use them.
Trip::with('routes')->with('vehicles')->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question