repository = $artwork; parent::__construct(); } /** * Display a list of artwork. * * @return Response */ public function index(ArtworkAdminWebRequest $request) { if ($request->wantsJson()) { $artworks = $this->repository->setPresenter('\\Cushbu\\Artwork\\Repositories\\Presenter\\ArtworkListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($artworks, 200); } $this ->theme->prependTitle(trans('artwork::artwork.names').' :: '); return $this->theme->of('artwork::admin.artwork.index')->render(); } /** * Display artwork. * * @param Request $request * @param Model $artwork * * @return Response */ public function show(ArtworkAdminWebRequest $request, Artwork $artwork) { if (!$artwork->exists) { return response()->view('artwork::admin.artwork.new', compact('artwork')); } Form::populate($artwork); return response()->view('artwork::admin.artwork.show', compact('artwork')); } /** * Show the form for creating a new artwork. * * @param Request $request * * @return Response */ public function create(ArtworkAdminWebRequest $request) { $artwork = $this->repository->newInstance([]); Form::populate($artwork); return response()->view('artwork::admin.artwork.create', compact('artwork')); } /** * Create new artwork. * * @param Request $request * * @return Response */ public function store(ArtworkAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $artwork = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('artwork::artwork.name')]), 'code' => 204, 'redirect' => trans_url('/admin/artwork/artwork/'.$artwork->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show artwork for editing. * * @param Request $request * @param Model $artwork * * @return Response */ public function edit(ArtworkAdminWebRequest $request, Artwork $artwork) { Form::populate($artwork); return response()->view('artwork::admin.artwork.edit', compact('artwork')); } /** * Update the artwork. * * @param Request $request * @param Model $artwork * * @return Response */ public function update(ArtworkAdminWebRequest $request, Artwork $artwork) { try { $attributes = $request->all(); $artwork->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('artwork::artwork.name')]), 'code' => 204, 'redirect' => trans_url('/admin/artwork/artwork/'.$artwork->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/artwork/artwork/'.$artwork->getRouteKey()), ], 400); } } /** * Remove the artwork. * * @param Model $artwork * * @return Response */ public function destroy(ArtworkAdminWebRequest $request, Artwork $artwork) { try { $t = $artwork->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('artwork::artwork.name')]), 'code' => 202, 'redirect' => trans_url('/admin/artwork/artwork/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/artwork/artwork/'.$artwork->getRouteKey()), ], 400); } } }