middleware(function ($request, $next) { $this->form = AgentForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('crm.agent.modules'), 'agent', guard_url('agent')); return $next($request); }); } /** * Display a list of agent. * * @return Response */ public function index(AgentResourceRequest $request) { $request = $request->all(); $page = AgentActions::run('paginate', $request); $data = new AgentsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('agent::agent.names')) ->view('agent::agent.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display agent. * * @param Request $request * @param Model $agent * * @return Response */ public function show(AgentResourceRequest $request, Agent $model) { $form = $this->form; $modules = $this->modules; $data = new AgentResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('agent::agent.name')) ->data(compact('data', 'form', 'modules')) ->view('agent::agent.show') ->output(); } /** * Show the form for creating a new agent. * * @param Request $request * * @return Response */ public function create(AgentResourceRequest $request, Agent $model) { $form = $this->form; $modules = $this->modules; $data = new AgentResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('agent::agent.name')) ->view('agent::agent.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new agent. * * @param Request $request * * @return Response */ public function store(AgentResourceRequest $request, Agent $model) { try { $request = $request->all(); $model = AgentAction::run('store', $model, $request); $data = new AgentResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('agent::agent.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('agent/agent/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/agent/agent')) ->redirect(); } } /** * Show agent for editing. * * @param Request $request * @param Model $agent * * @return Response */ public function edit(AgentResourceRequest $request, Agent $model) { $form = $this->form; $modules = $this->modules; $data = new AgentResource($model); // return view('agent::agent.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('agent::agent.name')) ->view('agent::agent.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the agent. * * @param Request $request * @param Model $agent * * @return Response */ public function update(AgentResourceRequest $request, Agent $model) { try { $request = $request->all(); $model = AgentAction::run('update', $model, $request); $data = new AgentResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('agent::agent.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('agent/agent/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('agent/agent/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the agent. * * @param Model $agent * * @return Response */ public function destroy(AgentResourceRequest $request, Agent $model) { try { $request = $request->all(); $model = AgentAction::run('destroy', $model, $request); $data = new AgentResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('agent::agent.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('agent/agent/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('agent/agent/' . $model->getRouteKey())) ->redirect(); } } }