repository = $company; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Company\Repositories\Criteria\CompanyResourceCriteria::class); } /** * Display a list of company. * * @return Response */ public function index(CompanyRequest $request) { return $this->repository ->setPresenter(\Litepie\Company\Repositories\Presenter\CompanyPresenter::class) ->paginate(); } /** * Display company. * * @param Request $request * @param Model $company * * @return Response */ public function show(CompanyRequest $request, Company $company) { return $company->setPresenter(\Litepie\Company\Repositories\Presenter\CompanyListPresenter::class); ; } /** * Create new company. * * @param Request $request * * @return Response */ public function store(CompanyRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('company::company.name')]); $code = 204; $status = 'success'; $url = guard_url('company/company/' . $company->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/company'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the company. * * @param Request $request * @param Model $company * * @return Response */ public function update(CompanyRequest $request, Company $company) { try { $data = $request->all(); $company->update($data); $message = trans('messages.success.updated', ['Module' => trans('company::company.name')]); $code = 204; $status = 'success'; $url = guard_url('company/company/' . $company->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/company/' . $company->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the company. * * @param Model $company * * @return Response */ public function destroy(CompanyRequest $request, Company $company) { try { $company->delete(); $message = trans('messages.success.deleted', ['Module' => trans('company::company.name')]); $code = 202; $status = 'success'; $url = guard_url('company/company/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/company/' . $company->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }