public function edit(Request $request, $id) { if ($request->has('type')) { $type = $request->input('type'); switch ($type) { case 'selectalarm': if ($id == 'no') { $available = AlarmType::where('entity_type', '=', 0)->get(); $existing = Alarm::where('entity_id', '=', 0)->get(); } else { $e = Entity::findOrFail($id); $available = $e->type->alarms; $existing = $e->alarms; } $structured = array(); foreach ($available as $a) { $unit = (object) array('alarm' => $a, 'pendings' => array()); foreach ($existing as $exist) { if ($exist->type->id == $a->id) { $unit->pendings[] = $exist; } } $structured[] = $unit; } return view('alarms.choosealarmtype', ['structured' => $structured]); break; } } else { $e = Entity::findOrFail($id); return view('entities.edit', ['entity' => $e]); } }
public static function getByTarget($target) { return AlarmType::where('entity_type', '=', $target->id)->get(); }