model = $car; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(CarAdminRequest $request) { if ($request->wantsJson()) { $array = $this->model->json(); foreach ($array as $key => $row) { $array[$key] = array_only($row, config('yoprueba.car.listfields')); } return ['data' => $array]; } $this->theme->prependTitle(trans('yoprueba::car.names').' :: '); return $this->theme->of('yoprueba::admin.car.index')->render(); } /** * Display the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function show(CarAdminRequest $request, $id) { $car = $this->model->find($id); if (empty($car)) { if ($request->wantsJson()) { return []; } return view('yoprueba::admin.car.new'); } if ($request->wantsJson()) { return $car; } Former::populate($car); return view('yoprueba::admin.car.show', compact('car')); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(CarAdminRequest $request) { $car = $this->model->findOrNew(0); Former::populate($car); return view('yoprueba::admin.car.create', compact('car')); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(CarAdminRequest $request) { try { $attributes = $request->all(); $car = $this->model->create($attributes); return $this->success(trans('messages.success.created', ['Module' => trans('yoprueba::car.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function edit(CarAdminRequest $request, $id) { $car = $this->model->find($id); Former::populate($car); return view('yoprueba::admin.car.edit', compact('car')); } /** * Update the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function update(CarAdminRequest $request, $id) { try { $attributes = $request->all(); $car = $this->model->update($attributes, $id); return $this->success(trans('messages.success.updated', ['Module' => trans('yoprueba::car.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(CarAdminRequest $request, $id) { try { $this->model->delete($id); return $this->success(trans('message.success.deleted', ['Module' => trans('yoprueba::car.name')]), 200); } catch (Exception $e) { return $this->error($e->getMessage()); } } }