41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Sector;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class SectorController extends Controller
|
|
{
|
|
public function index(): JsonResponse
|
|
{
|
|
$sectors = Sector::withCount([
|
|
'opportunities as opportunities_count' => fn ($q) => $q->published(),
|
|
])
|
|
->where('is_active', true)
|
|
->orderBy('sort_order')
|
|
->get()
|
|
->map(fn ($s) => [
|
|
'id' => $s->id,
|
|
'name' => $s->name,
|
|
'slug' => $s->slug,
|
|
'shortDescription' => $s->short_description,
|
|
'description' => $s->description,
|
|
'icon' => $s->icon,
|
|
'opportunitiesCount' => $s->opportunities_count,
|
|
'url' => "/sectores/{$s->slug}",
|
|
]);
|
|
|
|
return response()->json(['success' => true, 'data' => $sectors]);
|
|
}
|
|
|
|
public function show(string $slug): JsonResponse
|
|
{
|
|
$sector = Sector::with(['opportunities' => fn ($q) => $q->published()])
|
|
->where('slug', $slug)->firstOrFail();
|
|
|
|
return response()->json(['success' => true, 'data' => $sector]);
|
|
}
|
|
}
|