36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\Company;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CompanyController
|
|
{
|
|
/**
|
|
* Retrieve all published companies with their associated activity and sector.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getCompanies(): \Illuminate\Http\JsonResponse
|
|
{
|
|
$companies = Company::query()->where('published', true)->with('companyActivity', 'companySector')->get();
|
|
|
|
$data = $companies->map(function ($company) {
|
|
return array_filter([
|
|
'name' => $company->name,
|
|
'logo' => $company->logo,
|
|
'informations' => $company->informations,
|
|
'responsable' => $company->responsable,
|
|
'employees' => $company->employees,
|
|
'url' => $company->url,
|
|
'latitude' => $company->latitude,
|
|
'longitude' => $company->longitude,
|
|
'type_activite' => Str::lower($company->companyActivity->name),
|
|
'filiere' => $company->companySector?->name,
|
|
], fn($value) => !is_null($value));
|
|
});
|
|
|
|
return response()->json($data);
|
|
}
|
|
}
|