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