repository = $client; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Laraclass\Client\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(\Laraclass\Client\Repositories\Presenter\ClientPresenter::class) ->$function(); } $clients = $this->repository->paginate(); return $this->response->title(trans('client::client.names')) ->view('client::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 = 'client::client.show'; } else { $view = 'client::client.new'; } return $this->response->title(trans('app.view') . ' ' . trans('client::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('client::client.name')) ->view('client::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('client::client.name')])) ->code(204) ->status('success') ->url(guard_url('client/client/' . $client->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/client/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('client::client.name')) ->view('client::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('client::client.name')])) ->code(204) ->status('success') ->url(guard_url('client/client/' . $client->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('client/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('client::client.name')])) ->code(202) ->status('success') ->url(guard_url('client/client/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('client/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('client::client.name')])) ->status("success") ->code(202) ->url(guard_url('client/client')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/client/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('client::client.name')])) ->status("success") ->code(202) ->url(guard_url('/client/client')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/client/client/')) ->redirect(); } } }