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