class Invite extends Model
{
/**
* Get all of the owning invitable models.
*/
public function invitable()
{
return $this->morphTo();
}
}
class Storyteller extends Model
{
/**
* Get all of the owning storytellerable models.
*/
public function storytellerable()
{
return $this->morphTo();
}
}
class Exercise extends Model
{
/**
* Get all of the exercise's invites.
*/
public function invites()
{
return $this->morphMany('App\Invite', 'invitable');
}
/**
* Get all of the exercise's storytellers.
*/
public function storytellers()
{
return $this->morphMany('App\Storyteller', 'storytellerable');
}
}
Jan 15, 2018
2
Level 13
Help Figuring out the Proper Relationship
I have three tables.
exercises
- id
invites
- invitable_id == exercise->id
- invitable_type == App\Exercise
- email == [email protected]
storytellers
- storytellerable_id == exercise->id
- storytellerable_type == App\Exercise
- email == [email protected]
I need to be able to grab storyteller's invite($storyteller->invite) or a storyteller that belongs to an invite($invite->storyteller). I need to match the email, exercise ID, and the type.
I cannot wrap my head around how to make this work. Can someone help me out?
Please or to participate in this conversation.