PHP code example of proai / laravel-struct

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

    

proai / laravel-struct example snippets


use App\Structs\GeoLocation;
use ProAI\Struct\Struct;

class Address extends Struct
{
    public string $street;

    public string $city;

    public GeoLocation $geo_location;
}

$address = new Address([
    'street' => 'Baker Street',
    'city' => 'London',
    'geo_location' => [
        'latitude' => 51.52,
        'longitude' => -0.1566,
    ],
]);

$address->street
=> "Baker Street"

$address->country
=> App\Structs\GeoLocation { ... }

use App\Structs\Address;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $casts = [
        'address' => Address::class,
    ];
}

use App\Structs\Address;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $casts = [
        'address' => Address::class.':composed',
    ];
}

use App\Structs\Address;
use ProAI\Struct\Collection;

class AddressCollection extends Collection
{
    public $type = Address::class;
}