repository = $image; parent::__construct(); } /** * Display a list of image. * * @return Response */ public function index(ImageRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('file::image.names').' :: '); return $this->theme->of('file::admin.image.index')->render(); } /** * Display a list of image. * * @return Response */ public function getJson(ImageRequest $request) { $pageLimit = $request->input('pageLimit'); $images = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\File\\File\\Repositories\\Presenter\\ImageListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $images['recordsTotal'] = $images['meta']['pagination']['total']; $images['recordsFiltered'] = $images['meta']['pagination']['total']; $images['request'] = $request->all(); return response()->json($images, 200); } /** * Display image. * * @param Request $request * @param Model $image * * @return Response */ public function show(ImageRequest $request, Image $image) { if (!$image->exists) { return response()->view('file::admin.image.new', compact('image')); } Form::populate($image); return response()->view('file::admin.image.show', compact('image')); } /** * Show the form for creating a new image. * * @param Request $request * * @return Response */ public function create(ImageRequest $request) { $image = $this->repository->newInstance([]); Form::populate($image); return response()->view('file::admin.image.create', compact('image')); } /** * Create new image. * * @param Request $request * * @return Response */ public function store(ImageRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $image = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('file::image.name')]), 'code' => 204, 'redirect' => trans_url('/admin/file/image/'.$image->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show image for editing. * * @param Request $request * @param Model $image * * @return Response */ public function edit(ImageRequest $request, Image $image) { Form::populate($image); return response()->view('file::admin.image.edit', compact('image')); } /** * Update the image. * * @param Request $request * @param Model $image * * @return Response */ public function update(ImageRequest $request, Image $image) { try { $attributes = $request->all(); $image->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('file::image.name')]), 'code' => 204, 'redirect' => trans_url('/admin/file/image/'.$image->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/file/image/'.$image->getRouteKey()), ], 400); } } /** * Remove the image. * * @param Model $image * * @return Response */ public function destroy(ImageRequest $request, Image $image) { try { $t = $image->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('file::image.name')]), 'code' => 202, 'redirect' => trans_url('/admin/file/image/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/file/image/'.$image->getRouteKey()), ], 400); } } }