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