Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Category Dropdown: Second Composable

Premium
3 min read

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 of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

MM
Md Mahmudul Hasan ✓ Link copied!

You have added this line as a new line const 'selectedCategory = ref('')'... And you missed highlighting it... I assume povillas did not do that mistake, may be some of his team member did... But please keep in mind for a new learner like me, it becomes so much annoying... Please do not ignore these little things

N
Nerijus ✓ Link copied!

Thanks for the report. Don't forget that we are all humans and make mistakes :) look at it this way, you get an error or something doesn't work then you debug, it's a learning process! ;) good luck learning.

BR
Blas Rangel ✓ Link copied!

Yes, in fact I was thinking that maybe all the things you dont mention in the course is to force us find the solution ourselves so we can grasp better the key concepts and little traps of the development process. Thanks guys. Great work.

KA
KHALID ABDULMAJEED ✓ Link copied!

Could you please help with this error Uncaught (in promise) ReferenceError: ref is not defined

Sorry :) I miss this part " import { onMounted, ref } from "vue"; "