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