public function createForAsset(Request $request) { // Get the Asset. $assetId = $request->input('asset_id'); $asset = Asset::find($assetId); if (!$asset) { $this->alert('error', "No Asset #{$assetId}", false); return $this->view; } // Save the Contact. $contact = new Contact(); $contact->name = $request->input('name'); $contact->phone_1 = $request->input('phone_1'); $contact->phone_2 = $request->input('phone_2'); $contact->save(); // Then connect the two. $asset->contacts()->attach($contact->id); return redirect("assets/{$asset->id}#contacts"); }
public function edit($id) { if (!$this->user || !$this->user->isClerk()) { $this->alert('warning', 'Only Clerks are allowed to edit Assets.'); return redirect("assets/{$id}"); } $this->view->asset = Asset::find($id); $this->view->title = 'Editing Asset ' . $this->view->asset->identifier; $this->view->states = State::orderBy('name')->get(); $this->view->suburbs = Suburb::orderBy('name')->get(); $this->view->breadcrumbs = ['assets' => 'Assets', 'assets/' . $this->view->asset->id => $this->view->asset->identifier, 'assets/' . $this->view->asset->id . '/edit' => 'Edit']; return $this->view; }