repository = $image; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \File\File\Repositories\Criteria\ImageUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(ImageRequest $request) { $images = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('file::image.names')); return $this->theme->of('file::user.image.index', compact('images'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Image $image * * @return Response */ public function show(ImageRequest $request, Image $image) { Form::populate($image); return $this->theme->of('file::user.image.show', compact('image'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(ImageRequest $request) { $image = $this->repository->newInstance([]); Form::populate($image); $this->theme->prependTitle(trans('file::image.names')); return $this->theme->of('file::user.image.create', compact('image'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(ImageRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $image = $this->repository->create($attributes); return redirect(trans_url('/user/file/image')) -> with('message', trans('messages.success.created', ['Module' => trans('file::image.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Image $image * * @return Response */ public function edit(ImageRequest $request, Image $image) { Form::populate($image); $this->theme->prependTitle(trans('file::image.names')); return $this->theme->of('file::user.image.edit', compact('image'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Image $image * * @return Response */ public function update(ImageRequest $request, Image $image) { try { $this->repository->update($request->all(), $image->getRouteKey()); return redirect(trans_url('/user/file/image')) ->with('message', trans('messages.success.updated', ['Module' => trans('file::image.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(ImageRequest $request, Image $image) { try { $this->repository->delete($image->getRouteKey()); return redirect(trans_url('/user/file/image')) ->with('message', trans('messages.success.deleted', ['Module' => trans('file::image.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }