PHP code example of avertys / lighter

1. Go to this page and download the library: Download avertys/lighter 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/ */

    

avertys / lighter example snippets


class User extends Model
{
    use LighterTrait;

    protected $appends = ['fullname'];
}

$user = User::find(1);

return response()->json(
    $user->lighter()->keep(['name', 'address']);
, 200);

/*
{
    "name" : "Steve",
    "age" : "28" 
}
*/


$users = User::all();

return response()->json(
    lighter($users)->keep(['name', 'address']);
, 200);

/*
{
    "name" : "Steve",
    "age" : "28" 
},
{
    "name" : "John",
    "age" : "35" 
},
*/


$user = User::find(1);

return response()->json(
    lighter($user)->keep(['name', 'address']);
, 200);

/*
{
    "name" : "Steve",
    "age" : "28" 
},
{
    "name" : "John",
    "age" : "35" 
},
*/


$user = User::find(1);

return response()->json(
    lighter($user)->keep();
, 200);

/*
{
    "name" : "Steve",
    "age" : "28" 
},
{
    "name" : "John",
    "age" : "35" 
},
*/