Skip to content

Instantly share code, notes, and snippets.

@LukeTowers
Created February 13, 2017 16:13
Show Gist options
  • Save LukeTowers/3f0ce8f29351599f65bd93d1abdb8bf9 to your computer and use it in GitHub Desktop.
Save LukeTowers/3f0ce8f29351599f65bd93d1abdb8bf9 to your computer and use it in GitHub Desktop.
Tutorials
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