DEV Community

ilya
ilya

Posted on

laravel eloquent relation

This is table relation

 $result = Event::select('events.*', 'events.at as datatime', 'events.end_time as endtime','event_types.name as event_type_name')
        ->from('events')
        ->leftJoin('event_types', 'event_types.id', 'events.type_id')
        ->where('events.id', $id)
        ->where('events.user_id', 350)
        ->get()
        ->toArray();
    return $result;
Enter fullscreen mode Exit fullscreen mode

i want to change it to eloquent relation.
for example, i think we can use with() method instead of select method of query.

Top comments (0)