/** * Remove the specified model device from storage. * * @param int $id * @return string */ public function destroy($id) { $modeldevices = ModelDevice::find($id); if ($modeldevices != null) { $modeldevices->delete(); } return json_encode("success"); }
/** * Display a listing of the resource. * * @return Response */ public function index() { if (\Request::ajax()) { $typedevices = TypeDevice::all(); return json_encode($typedevices); } if (\Request::ajax()) { $modeldevices = ModelDevice::all(); return json_encode($modeldevices); } return view('typedevices.index'); }
/** * Filter info in overview device * @return void */ public function filter() { $type_id = Input::get('type_device'); $model_id = Input::get('model_device'); $kind_id = Input::get('kind_device'); $status_id = Input::get('status_device'); $os_id = Input::get('os_device'); $contract_id = Input::get('contract_number'); $position = Position::all(); $types = TypeDevice::all(); $models = ModelDevice::all(); $kinds = KindDevice::all(); $statuses = StatusDevice::all(); $os = OperatingSystem::all(); $contract = InformationDevice::all(); /*Thuc hien cau truy van de lay du lieu sau khi filter*/ $devices = Device::whereHas('kind_device', function ($query) use($type_id) { if ($type_id) { $query->whereHas('model_device', function ($query) use($type_id) { $query->whereHas('type_devices', function ($query) use($type_id) { $query->where('id', '=', $type_id); }); }); } })->whereHas('kind_device', function ($query) use($model_id) { if ($model_id) { $query->whereHas('model_device', function ($query) use($model_id) { $query->where('id', '=', $model_id); }); } })->whereHas('kind_device', function ($query) use($kind_id) { if ($kind_id) { $query->where('id', '=', $kind_id); } })->whereHas('status_devices', function ($query) use($status_id) { if ($status_id) { $query->where('id', '=', $status_id); } })->whereHas('operating_system', function ($query) use($os_id) { if ($os_id) { $query->where('id', '=', $os_id); } })->whereHas('infomation_device', function ($query) use($contract_id) { if ($contract_id) { $query->where('id', '=', $contract_id); } })->get(); foreach ($devices as $key => $value) { $value->device_name = $value->kind_device->device_name; $value->status = $value->status_devices->status; $employee = $value->employee; if ($employee) { $value->employee_code = $employee->employee_code; $value->fullname = $employee->lastname . " " . $employee->firstname; $value->employee_position = $employee->departments['name']; } else { $value->employee_code = ""; $value->fullname = ""; $value->employee_position = ""; } } echo json_encode($devices); }