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