Laravel API Resource for API end point

I need to get the Json objects when I call the Get request http://myapp.com/api/products API end point

First thing you have do is create the normal controller using following artisan command

And create the Product model too

Then you create the resource controller at App\Http\Resources location

Which will produce thw folllwong code

In your App\Http\Controllers\ProductController file you need to add following code

Add the followoing code below the namespace of this class

use App\Http\Resources\Plan as ProductResource;

Now you have to define api route. In you routes\api.php file you can add the following code