In this lesson, we will create a dropdown select to pick from a list of categories. For this, we will create a new composable and a new API endpoint with the API Resource.
Let's start this lesson by creating a Controller with the API route.
php artisan make:controller Api/CategoryControllerphp artisan make:resource CategoryResource
app/Http/Controllers/Api/CategoryController.php:
use App\Http\Resources\CategoryResource; class CategoryController extends Controller{ public function index() { return CategoryResource::collection(Category::all()); }}
routes/api.php:
Route::get('posts', [PostController::class, 'index']);Route::get('categories', [CategoryController::class, 'index']);
In the Resource, we will only add...