I am using Laravel 5.5.13.
I have a model called Thumb
. This thumb is related to two things in a many-to-one relationship: Player
and Comment
.
I currently do things like this:
public function store(Request $request, Entity $entity, Player $player)
{
$thumb = new Thumb($request->all());
$thumb->player_id = $player->id;
$entity->thumbs()->save($thumb);
return response()->json($thumb, 201);
}
We see how I have to set $thumb->player_id
AND I don't have to set the entity_id
because I am doing $entity->thumbs()->save
Is there a way to do $entityAndPlayer->thumbs()->save
? Or is the way I did it above the recommend way?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ykAQpY
via IFTTT
Aucun commentaire:
Enregistrer un commentaire