/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $device = Device::current(); if (Input::hasFile('file')) { $inputFile = Input::file('file'); $package = Package::createFromInputFile($inputFile, $device->user_id); } else { $package = Package::findOrFailFromArg(Input::get('package'), $device->user_id); } $ids = explode(',', Input::get('devices')); if (count($ids) == 1 && !is_numeric($ids[0])) { $token = Token::whereValue($ids[0])->valid()->first(); if ($token) { $devices = Device::whereId($token->owner)->get(); } else { return Response::error(trans('errors.expired_device_qrcode') . $ids[0], 400); } } if (empty($devices)) { $devices = Device::whereIn('id', $ids)->where(function ($query) use($device) { $query->whereUserId($device->user_id)->orWhere(function ($query) use($device) { $authed_device_ids = DUAuth::whereUserId($device->user_id)->lists('device_id'); $query->whereIn('id', $authed_device_ids); }); })->get(); } try { $push = Push::send($devices, $package, $device->user_id); return Response::json($push); } catch (\Exception $e) { return Response::exception($e); } }
public function getIndex() { $devices = Device::whereUserId(Auth::id())->orWhere(function ($query) { $authed_device_ids = DUAuth::whereUserId(Auth::id())->lists('device_id'); $query->whereIn('id', $authed_device_ids); })->paginate(15); return View::make('device.index')->with('devices', $devices); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\JsonResponse */ public function index() { $device = Device::current(); $devices = Device::where(function ($query) use($device) { $query->whereUserId($device->user_id)->where('id', '<>', $device->id); })->orWhere(function ($query) use($device) { $authed_device_ids = DUAuth::whereUserId($device->user_id)->lists('device_id'); $query->whereIn('id', $authed_device_ids); })->paginate(15); return Response::json($devices); }
/** * 选择设备 */ public function getTarget() { $devices = Device::whereUserId(Auth::id())->orWhere(function ($query) { $authed_device_ids = DUAuth::whereUserId(Auth::id())->lists('device_id'); $query->whereIn('id', $authed_device_ids); })->get(); $response = View::make('install.target')->with('devices', $devices); if (Input::has('package')) { $package = Package::findOrFailFromArg(Input::get('package'), Auth::id()); return $response->with('package', $package); } else { $url = Input::old('url'); if (empty($url)) { return redirect('install')->withToast('发生异常'); } return $response->with('url', $url); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { /** * @var DUAuth $auth */ $auth = DUAuth::whereDeviceId($this->device->id)->findOrFail($id); if (!$auth) { return Response::error(Lang::get('errors.forbidden', 403)); } $auth->delete(); return Response::noContent(); }