companies()->collect(); return $this->response->paginator($companies, new Transformer()); } /** * Display the specified resource. * * @param Company $company * @return \Dingo\Api\Http\Response */ public function show(Company $company) { try { // Check if user can access company $this->owner($company); return $this->response->item($company, new Transformer()); } catch (\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } /** * Store a newly created resource in storage. * * @param $request * @return \Dingo\Api\Http\Response */ public function store(Request $request) { $company = $this->dispatch(new CreateCompany($request)); return $this->response->created(url('api/companies/' . $company->id)); } /** * Update the specified resource in storage. * * @param $company * @param $request * @return \Dingo\Api\Http\Response */ public function update(Company $company, Request $request) { try { $company = $this->dispatch(new UpdateCompany($company, $request)); return $this->item($company->fresh(), new Transformer()); } catch (\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } /** * Enable the specified resource in storage. * * @param Company $company * @return \Dingo\Api\Http\Response */ public function enable(Company $company) { try { $company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 1]))); return $this->item($company->fresh(), new Transformer()); } catch (\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } /** * Disable the specified resource in storage. * * @param Company $company * @return \Dingo\Api\Http\Response */ public function disable(Company $company) { try { $company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 0]))); return $this->item($company->fresh(), new Transformer()); } catch (\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } /** * Remove the specified resource from storage. * * @param Company $company * @return \Dingo\Api\Http\Response */ public function destroy(Company $company) { try { $this->dispatch(new DeleteCompany($company)); return $this->response->noContent(); } catch (\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } /** * Check user company assignment * * @param Company $company * * @return \Dingo\Api\Http\Response */ public function owner(Company $company) { if ($this->isUserCompany($company->id)) { return new Response(''); } $message = trans('companies.error.not_user_company'); $this->response->errorUnauthorized($message); } }