1. Go to this page and download the library: Download maxkut/model-entities 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/ */
maxkut / model-entities example snippets
// Как пример сложных json полей модели App\Models\User
namespace App\Models\Entities\User;
use Entities\Entity;
/**
* Class Settings
* @property bool $property1
* @property int $property2
* @property array $property3
*/
class Settings extends Entity
{
/**
* @var bool $strictParams - если true,
* то любые свойства, которые не объявлены в $attributes, $casts
или для него нет акцессора/мутатора
* вызовут исключение Entities\Exceptions\NotDefinedPropertyException
*/
public $strictParams = true;
protected $attributes = [
'property1' => null,
'property2' => null,
'property3' => null,
];
protected $casts = [
'property1' => 'bool',
'property2' => 'int',
'property3' => 'array',
];
}
///////////////////////////////////////////
/// На примере моделей Eloquent ORM
/// надо создать методы преобразования (акцессор и мутатор) для этого поля
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Entities\User\Settings;
class User extends Model
{
//...
protected function getSettingsAttribute($value){
return Settings::make($value);
}
protected function setSettingsAttribute($value){
$this->attributes['settings'] = Settings::make($value)->toJson();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.