repository = $broker; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Broker\Repositories\Criteria\BrokerResourceCriteria::class); } /** * Display a list of broker. * * @return Response */ public function index(BrokerRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Broker\Repositories\Presenter\BrokerPresenter::class) ->$function(); } $brokers = $this->repository->paginate(); return $this->response->title(trans('broker::broker.names')) ->view('broker::broker.index', true) ->data(compact('brokers', 'view')) ->output(); } /** * Display broker. * * @param Request $request * @param Model $broker * * @return Response */ public function show(BrokerRequest $request, Broker $broker) { if ($broker->exists) { $view = 'broker::broker.show'; } else { $view = 'broker::broker.new'; } return $this->response->title(trans('app.view') . ' ' . trans('broker::broker.name')) ->data(compact('broker')) ->view($view, true) ->output(); } /** * Show the form for creating a new broker. * * @param Request $request * * @return Response */ public function create(BrokerRequest $request) { $broker = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('broker::broker.name')) ->view('broker::broker.create', true) ->data(compact('broker')) ->output(); } /** * Create new broker. * * @param Request $request * * @return Response */ public function store(BrokerRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $broker = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('broker::broker.name')])) ->code(204) ->status('success') ->url(guard_url('broker/broker/' . $broker->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/broker/broker')) ->redirect(); } } /** * Show broker for editing. * * @param Request $request * @param Model $broker * * @return Response */ public function edit(BrokerRequest $request, Broker $broker) { return $this->response->title(trans('app.edit') . ' ' . trans('broker::broker.name')) ->view('broker::broker.edit', true) ->data(compact('broker')) ->output(); } /** * Update the broker. * * @param Request $request * @param Model $broker * * @return Response */ public function update(BrokerRequest $request, Broker $broker) { try { $attributes = $request->all(); $broker->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('broker::broker.name')])) ->code(204) ->status('success') ->url(guard_url('broker/broker/' . $broker->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('broker/broker/' . $broker->getRouteKey())) ->redirect(); } } /** * Remove the broker. * * @param Model $broker * * @return Response */ public function destroy(BrokerRequest $request, Broker $broker) { try { $broker->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('broker::broker.name')])) ->code(202) ->status('success') ->url(guard_url('broker/broker/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('broker/broker/' . $broker->getRouteKey())) ->redirect(); } } /** * Remove multiple broker. * * @param Model $broker * * @return Response */ public function delete(BrokerRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('broker::broker.name')])) ->status("success") ->code(202) ->url(guard_url('broker/broker')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/broker/broker')) ->redirect(); } } /** * Restore deleted brokers. * * @param Model $broker * * @return Response */ public function restore(BrokerRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('broker::broker.name')])) ->status("success") ->code(202) ->url(guard_url('/broker/broker')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/broker/broker/')) ->redirect(); } } }