Created
February 13, 2017 16:13
-
-
Save LukeTowers/3f0ce8f29351599f65bd93d1abdb8bf9 to your computer and use it in GitHub Desktop.
Tutorials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StaffMembersController::extendFormFields(function($form, $model, $context) { | |
if (!$model instanceof StaffMemberModel) { | |
return; | |
} | |
// Get the model's profile, including any that may have been deferred already | |
$profile = $model->profile()->withDeferred($form->getSessionKey())->first(); | |
// If the profile object for this user doesn't exist yet, then create it and add it via deferred binding if necessary | |
if (!$profile) { | |
$profile = new ProfileModel(); | |
if ($model->exists) { | |
$profile->user_id = $model->id; | |
$profile->save(); | |
} else { | |
$model->profile()->add($profile, $form->getSessionKey()); | |
} | |
} | |
// Assign the profile object to the user profile relation for the form to use | |
$model->profile = $profile; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment