should I use resource collection in this example ?
Hello , I was wondering if i should use resource collection to pass the courses ,
this program/create js file to create a new program , and i pass courses to select the courses that will be taught in the program. i already have course resource and resource collection but this needs only id , name
public function create()
{
$courses = Course::all('id','name');
return Inertia::render('Program/Create', [ 'courses' => $courses ]);
}
Why not? Resource collections are great for passing data around, and it looks like you've already got the code set up for it. Plus, you get the added bonus of being able to say you're using a resource collection, which is always a plus in my book.
It is not absolutely required in this case where you are being explicit about the database columns to select in the query. In any case where you are not being so explicit, however, you will expose potentially sensitive/unwanted data.
In general, my preference is to decouple the response payload from the database anyway; so I would create and return a UserResource instance anyway.