1. Go to this page and download the library: Download zero-to-prod/data-model 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/ */
zero-to-prod / data-model example snippets
trait DataModel extends \Zerotoprod\DataModel\DataModel
{
// Add additional utility methods and traits
}
class User
{
use DataModel;
public $name;
public $email;
/** @var \App\Address $Address */
public Address;
}
namespace App;
class Address
{
use DataModel;
public $street;
}
$user = User::from(
[
'name' => 'John Doe',
'email' => '[email protected]',
'Address' => ['street' => '456 Memory Lane']
]
);
echo $user->name; // 'John Doe'
echo $user->email; // '[email protected]'
echo $user->Address->street; // '456 Memory Lane'
/** @var Address $Address */
public $Address;
/** @var \App\Address $Address */
class User
{
use \Zerotoprod\DataModel\DataModel;
use \Zerotoprod\DataModel\FromJson;
public $name;
public $email;
}
$user = User::fromJson('"name":"John", "email":"[email protected]"');
$user->name; // 'John'
$user->email; // '[email protected]'
class YourDataModel
{
use \Zerotoprod\DataModel\DataModel;
use \Zerotoprod\Transformable\Transformable;
public $name;
public $email;
}
$model = new YourDataModel();
$array = $model->toArray();
$json = $model->toJson();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.