H
H
Harconnen2015-06-07 17:27:31
Laravel
Harconnen, 2015-06-07 17:27:31

How to do join in Laravel if belongTo is used?

Hello!
Laravel started using recently.
i have working code

return Tour::find($tour->id)->trips()
                ->where('active', '=', '1')
                ->orderBy('top', 'sort')
                ->paginate(10);

The ' trips ' table has a ' trip_places_id ' field and there is a ' places ' table from which you need to extract a record if
trips.trip_places_id = places.id
But I don’t know how to make a join correctly.
Sincerely, Konstantin.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-06-07
@Harconnen

So write:

return Tour::find($tour->id)->trips()->with('places')
                ->where('active', '=', '1')
                ->orderBy('top', 'sort')
                ->paginate(10);

Of course Trips must have a relationship places -> belongsTo('Place')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question