PHP code example of lasselehtinen / cybertron

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

    

lasselehtinen / cybertron example snippets


class TestModel extends Model
{
    /**
     * Example hasMany relationship
     */
    public function hasManySomethings()
    {
        return $this->hasMany(SomeOtherModel::class);
    }
}

    public function up()
    {
        Schema::create('test_models', function (Blueprint $table) {
            $table->increments('id_field');
            $table->boolean('boolean_field');
            $table->string('string_field');
        });
    }



namespace App;

use League\Fractal;
use \lasselehtinen\Cybertron\Tests\TestModel;

class TestTransformer extends Fractal\TransformerAbstract
{
    /**
     * List of resources to automatically   array
     */
    public function transform(TestModel $testModel)
    {
        return [
            'id_field' => (integer) $testModel->id_field,
            'boolean_field' => (boolean) $testModel->boolean_field,
            'string_field' => $testModel->string_field,
        ];
    }

    /**
     * Include HasManySomethings
     *
     * @param  TestModel $testModel
     * @return \League\Fractal\Resource\Collection
     */
    public function 

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register(lasselehtinen\Cybertron\CybertronServiceProvider::class);
    }
}
bash
php artisan make:transformer PostTransformer --model=\\App\\Post