all(); $upload = UploadWorkflow::run($trasition, $upload, $request); $data = new UploadResource($upload); return $this->response->message(trans('messages.success.updated', ['Module' => trans('database::upload.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('database/upload/' . $upload->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('database/upload/' . $upload->getRouteKey())) ->redirect(); } } /** * Get the upload and user for the workflow. * * @param PublicRequest $request * @param string $upload * @param string $user * * @return Response */ public function get(PublicRequest $request, $upload, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $upload = Upload::findBySignedId($upload); $transitions = $this->transitions($upload, $user); $user = user(); Auth::logout(); return $this->response->setMetaTitle(trans('database::upload.name') . ' ' . trans('Approvals')) ->view('database::public.upload.workflow') ->layout('mobile') ->data(compact('upload', 'user', 'transitions')) ->output(); } /** * Display the workflow form for the upload. * * @param PublicRequest $request * @param string $upload * @param string $user * * @return Response */ public function post(PublicRequest $request, $upload, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $transition = $request->transition; $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $upload = Upload::findBySignedId($upload); $user = user(); $upload = UploadWorkflow::run($transition, $upload, $request->all()); Auth::logout(); return response()->json( [ 'status' => 'success', 'url' => $request->url(), ] ); } private function transitions($upload, $user) { $transitions = []; foreach ($upload->workflow()->transitions($upload) as $key => $value) { $name = $value->getName(); $array['url'] = URL::temporarySignedRoute('litecms.upload.workflow', now()->addMinutes(3), [ 'guard' => 'admin', 'transition' => $name, 'upload' => $upload->getSignedId(now()->addMinutes(3)), 'user' => $user->getSignedId(now()->addMinutes(3)), 'trans' => 'en', ] ); $array['name'] = $name; $array['key'] = $name; $array['form'] = $upload->workflow()->form($value); $array['label'] = trans('database::upload.workflow.' . $name); $transitions[] = $array; } return $transitions; } }