php artisan make:resource User created a resource with the following code for me:
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class User extends Resource
{
...
When i hooked my controller, resource and model together like so:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use App\Http\Resources\User as UserResource;
class UserController extends Controller
{
...
public function index()
{
// fetch all users
$users= Patient::paginate(15);
// return userscollection
return UserResource::collection($users);
}
....
and when i did a GET request for /api/users , I get a 500 server error with message 'Class 'App\Http\Resources\Resource' not found in \ApiTutorial\app\Http\Resources\User.php on line 7'
I manually changed my resource to extend JsonResource instead of Resource and this resolved the issue for me. I also then fixed resource.stub and recreated my resource and that also worked as expected. I could submit a PR is that's okay?
Here is a snippet of my composer.json in case that is needed:
php artisan make:resource User created a resource with the following code for me:
When i hooked my controller, resource and model together like so:
and when i did a GET request for /api/users , I get a 500 server error with message 'Class 'App\Http\Resources\Resource' not found in \ApiTutorial\app\Http\Resources\User.php on line 7'
I manually changed my resource to extend JsonResource instead of Resource and this resolved the issue for me. I also then fixed resource.stub and recreated my resource and that also worked as expected. I could submit a PR is that's okay?
Here is a snippet of my composer.json in case that is needed: