PHP code example of jasonej / enhanced-resources

1. Go to this page and download the library: Download jasonej/enhanced-resources library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jasonej / enhanced-resources example snippets




use Illuminate\Http\Resources\Json\JsonResource;
use Jasonej\EnhancedResources\EnhancedResource;

class Resource extends JsonResource
{
    use EnhancedResource;
}



use Illuminate\Http\Resources\Json\ResourceCollection;
use Jasonej\EnhancedResources\EnhancedCollection;

class Collection extends ResourceCollection
{
    use EnhancedCollection;
}



$user = User::find(1);

Resource::make($user)->response();

Resource::make($user)->append(['name'])->response();

Resource::make($user)->exclude(['id', 'secret'])->response();

Resource::make($user)->only(['first_name', 'last_name'])->response();