-
app/Http/Resources/Company/Company.php
Open in GitHubuse App\Helpers\DateHelper; use Illuminate\Http\Resources\Json\JsonResource; class Company extends JsonResource { public function toArray($request) { return [ 'id' => $this->id, 'object' => 'company', 'name' => $this->name, 'website' => $this->website, 'number_of_employees' => $this->number_of_employees, 'account' => [ 'id' => $this->account_id, ], 'created_at' => DateHelper::getTimestamp($this->created_at), 'updated_at' => DateHelper::getTimestamp($this->updated_at), ]; } }
-
app/Http/Controllers/Api/Account/ApiCompanyController.php
Open in GitHubuse App\Http\Resources\Company\Company as CompanyResource; use App\Http\Controllers\Api\ApiController; class ApiCompanyController extends ApiController { public function index(Request $request) { try { $companies = auth()->user()->account->companies() ->orderBy($this->sort, $this->sortDirection) ->paginate($this->getLimitPerPage()); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return CompanyResource::collection($companies); } public function show(Request $request, $companyId) { try { $company = Company::where('account_id', auth()->user()->account_id) ->where('id', $companyId) ->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } return new CompanyResource($company); } // }