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