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