middleware(function ($request, $next) { $this->form = VehicleForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('eform.vehicle.modules'), 'vehicle', guard_url('vehicle')); return $next($request); }); } /** * Display a list of vehicle. * * @return Response */ public function index(VehicleResourceRequest $request) { $request = $request->all(); $page = VehicleActions::run('paginate', $request); $data = new VehiclesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('vehicle::vehicle.names')) ->view('vehicle::vehicle.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display vehicle. * * @param Request $request * @param Model $vehicle * * @return Response */ public function show(VehicleResourceRequest $request, Vehicle $model) { $form = $this->form; $modules = $this->modules; $data = new VehicleResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('vehicle::vehicle.name')) ->data(compact('data', 'form', 'modules')) ->view('vehicle::vehicle.show') ->output(); } /** * Show the form for creating a new vehicle. * * @param Request $request * * @return Response */ public function create(VehicleResourceRequest $request, Vehicle $model) { $form = $this->form; $modules = $this->modules; $data = new VehicleResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('vehicle::vehicle.name')) ->view('vehicle::vehicle.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new vehicle. * * @param Request $request * * @return Response */ public function store(VehicleResourceRequest $request, Vehicle $model) { try { $request = $request->all(); $model = VehicleAction::run('store', $model, $request); $data = new VehicleResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('vehicle::vehicle.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('vehicle/vehicle/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/vehicle/vehicle')) ->redirect(); } } /** * Show vehicle for editing. * * @param Request $request * @param Model $vehicle * * @return Response */ public function edit(VehicleResourceRequest $request, Vehicle $model) { $form = $this->form; $modules = $this->modules; $data = new VehicleResource($model); // return view('vehicle::vehicle.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('vehicle::vehicle.name')) ->view('vehicle::vehicle.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the vehicle. * * @param Request $request * @param Model $vehicle * * @return Response */ public function update(VehicleResourceRequest $request, Vehicle $model) { try { $request = $request->all(); $model = VehicleAction::run('update', $model, $request); $data = new VehicleResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('vehicle::vehicle.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('vehicle/vehicle/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('vehicle/vehicle/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the vehicle. * * @param Model $vehicle * * @return Response */ public function destroy(VehicleResourceRequest $request, Vehicle $model) { try { $request = $request->all(); $model = VehicleAction::run('destroy', $model, $request); $data = new VehicleResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('vehicle::vehicle.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('vehicle/vehicle/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('vehicle/vehicle/' . $model->getRouteKey())) ->redirect(); } } }