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