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