S0PEX's avatar
Level 1

Pass relationships when calling Model::create($request->all()) ?

Hey,

so at the moment, I have a trait which provides the basic functionality for my controllers like all(), store() etc. But now I am facing an issue where my form submits basic information for the model and then also some relationship stuff where the user can select other subscriptions attached to the object. Subs

so what I am doing atm is this :

        $this->validate($request, $m::$rules);
        $cheatData = $request->input('cheat');
        $cheat = Cheat::create( $cheatData );
        $user_upgrades = $cheatData['user_upgrade_binds'];
        $cheat->UserUpgrades()->sync($user_upgrades);
        return response()->json(['status' => 'success']);

I know I should probably wrap the whole method in a db transaction.

Is where a way to pass this php $cheatData['user_upgrade_binds']; diretly while creating the object on php Cheat::create( $cheatData, $binding ??? );

Regards S0PEX

0 likes
1 reply
martinbean's avatar

@S0PEX I’m not sure I feel comfortable trying to answer a question by someone selling “cheats” for a game I enjoy playing. It’s bad enough having to put up with people in Deluxos let alone actual cheaters as well.

Please or to participate in this conversation.