LARAVEL's resource classes allow you to expressively and easily transform your models and model collections into JSON.Basically you can generate a nice json formatted data right from Eloquent. Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON. Let’s learn how to generate api resources.Consider you have a user table in your database and you want to generate api resources for your User model.Run following command on your terminal window while being on laravel project root directory:
- Run this Command to generate a resource class.
- By default, resources will be placed in the
app/Http/Resources
directory of your application. Resources extend theIlluminate\Http\Resources\Json\JsonResource
class: