How can I use JSON API Resource in a Lumen project?

API Resources are available in lumen, the files are there under: vendor\illuminate\http\Resources. what's missing is the artisan command to generate them. So just create the files manually, something like: app\Http\Resources\UserResource.php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'name' => $this->name,
            'email' => $this->email,
        ];
    }
}

I don't know who says, API Resources is not meant for Lumen, but that's not true.

Tags:

Php

Laravel

Lumen