repository = $block; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(BlockUserWebRequest $request) { $this->repository->pushCriteria(new \Lavalite\Block\Repositories\Criteria\BlockUserCriteria()); $blocks = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('block::block.names').' :: '); return $this->theme->of('block::user.block.index', compact('blocks'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Block $block * * @return Response */ public function show(BlockUserWebRequest $request, Block $block) { Form::populate($block); return $this->theme->of('block::user.block.show', compact('block'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(BlockUserWebRequest $request) { $block = $this->repository->newInstance([]); Form::populate($block); return $this->theme->of('block::user.block.create', compact('block'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(BlockUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $block = $this->repository->create($attributes); return redirect(trans_url('/user/block/block')) -> with('message', trans('messages.success.created', ['Module' => trans('block::block.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 Block $block * * @return Response */ public function edit(BlockUserWebRequest $request, Block $block) { Form::populate($block); return $this->theme->of('block::user.block.edit', compact('block'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Block $block * * @return Response */ public function update(BlockUserWebRequest $request, Block $block) { try { $this->repository->update($request->all(), $block->getRouteKey()); return redirect(trans_url('/user/block/block')) ->with('message', trans('messages.success.updated', ['Module' => trans('block::block.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(BlockUserWebRequest $request, Block $block) { try { $this->repository->delete($block->getRouteKey()); return redirect(trans_url('/user/block/block')) ->with('message', trans('messages.success.deleted', ['Module' => trans('block::block.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }