36 lines
772 B
PHP
36 lines
772 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Controllers\Api;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Resources\JobCategoryResource;
|
||
|
|
use App\Models\JobCategory;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class JobCategoryController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Display a listing of job categories
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
$categories = JobCategory::withCount('jobs')
|
||
|
|
->orderBy('name')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return JobCategoryResource::collection($categories);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified category
|
||
|
|
*/
|
||
|
|
public function show(string $slug)
|
||
|
|
{
|
||
|
|
$category = JobCategory::where('slug', $slug)
|
||
|
|
->withCount('jobs')
|
||
|
|
->firstOrFail();
|
||
|
|
|
||
|
|
return new JobCategoryResource($category);
|
||
|
|
}
|
||
|
|
}
|