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