Skip to content

Instantly share code, notes, and snippets.

@dvlpp
Created December 18, 2019 16:43
Show Gist options
  • Save dvlpp/81b4963b8036e3c4a0eb470f8544f992 to your computer and use it in GitHub Desktop.
Save dvlpp/81b4963b8036e3c4a0eb470f8544f992 to your computer and use it in GitHub Desktop.
PilotSharpForm
<?php
class PilotSharpForm extends SharpForm
{
use WithSharpFormEloquentUpdater, WithSharpContext;
// [...]
function update($id, array $data)
{
$pilot = $id ? Pilot::findOrFail($id) : new Pilot;
$pilot = $this->save($pilot, $data);
if($this->context()->isCreation()) {
if($breadcrumb = $this->context()->getPreviousPageFromBreadcrumb("show")) {
list($type, $entityKey, $instanceId) = $breadcrumb;
if ($entityKey == "spaceship") {
Spaceship::findOrFail($instanceId)->pilots()->attach($pilot->id);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment