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