PHP code example of homesheer / laravel-assembler

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

    

homesheer / laravel-assembler example snippets


// config/app.php
HomeSheer\LaravelAssembler\AssemblerServiceProvider::class,

// bootstrap/app.php
$app->register(HomeSheer\LaravelAssembler\AssemblerServiceProvider::class);

$assembler = new Assembler(User::find($id));

$assembledUserData = $assembler->getAssembledData();

return $this->response($assembledUserData);

class UserAssembler extends Assembler
{
    public function getVirtualField()
    {
        return 'VirtualField';
    }
}

class User
{
    public function getName()
    {
        return 'Mars';
    }
}

class User
{
    public $name = 'Mars';
}

$user = [
    'name' => 'Mars',
];
bash
php artisan vendor:publish --provider="HomeSheer\LaravelAssembler\AssemblerServiceProvider" --tag="config"