Let
2 years ago

Need help for naming eloquent relations

Posted 2 years ago by Let

Hi,

I have 2 tables :

- users
- events

An user can

  • publish an event (he's creating his event)
  • organize an event (he's been asked by someone else to be among the organizers)
  • participate to an event (he'll go to the event)

Now, I want to define these relations in my Eloquent models. Here is what I've done so far.

Event.php

<?php

class Event extends Eloquent
{
    /**
     * Get the publisher of the event.
     */
    public function publisher()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Get the organizers of the event.
     */
    public function organizers()
    {
        return $this->belongsToMany(User::class);
    }

    /**
     * Get the participants of the event.
     */
    public function participants()
    {
        return $this->belongsToMany(User::class);
    }

}

And User.php

<?php

class User extends Eloquent
{
    /**
     * Get the events created by the user.
     */
    public function events()
    {
        return $this->hasMany(Event::class);
    }

    /**
     * Get the events organized by the user.
     */
    public function xxx()
    {
        return $this->belongsToMany(Event::class);
    }

    /**
     * Get the events the user is participating.
     */
    public function yyy()
    {
        return $this->belongsToMany(Event::class);
    }

}

How would you rename xxx() and yyy() methods of User.php class ?

Thank you

Please sign in or create an account to participate in this conversation.