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