Courses

Vue.js 3 + Laravel 11 API + Vite: SPA CRUD

Category Dropdown: Second Composable

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Creating category composable for reusability
- Setting up categories API endpoint
- Building dropdown component for filtering
- Implementing category selection interface

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.

categories select list


Let's start this lesson by creating a Controller with the API route.

php artisan make:controller Api/CategoryController
php 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...

The full lesson is only for Premium Members.
Want to access all 27 lessons of this course? (115 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord