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