Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

It does have this functionality.

class Event ... 
{
    public function creator()
    {
        return $this->belongsTo('User'); // assuming user_id
    }
    public function attendees()
    {
        return $this->belongsToMany('User'); // assumes a pivot table event_user
    }
}


$event = Event::with('creator', 'attendees')->find($id);

$event->creator->name; // Bob
$event->attendees->count(); // 4

Also Event is an existing class already in Laravel and is Aliased. So I imagine this was changed already in your app.

'Event' => 'Illuminate\Support\Facades\Event',
Last updated 2 years ago.
0

Thanks, this is exactly what I wanted, and yes, i wasnt using event, my actual use case is a lot more abstract, i picked this example because its easier to understand

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

quirkles quirkles Joined 1 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.