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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay