PHP code example of joecianflone / modelproperties

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

    

joecianflone / modelproperties example snippets


class User extends Model {

    protected $fillable = ['name', 'email', 'password', 'role', 'is_active'];

    protected $hidden = ['password', 'remember_token'];

    protected $casts = [
        'id' => 'string',
        'role' => UserRole::class
        'is_active' => 'boolean',
        'email_activated_at' => 'datetime',
        'remember_token' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    protected $attributes = [
        'role' => UserRole::STANDARD
        'is_active' => true,
    ];
}

#[ModelProperties(
    id:  ['string', 'is:primary' 'auto-increment' => false],         
    name:  ['string', 'is:fillable'],      
    email:  ['string', 'is:fillable'],
    password:  ['hashed', 'is:hidden|fillable'],   
    role: [UserRole::class => UserRole::STANDARD], 
    is_active:          ['boolean' => true],
    remember_token:     ['string', 'is:hidden'],
    email_verified_at:  ['datetime'],
    created_at:         ['datetime'],
    updated_at:         ['datetime'],
)]
class User extends Model {

    use HasModelProperties;

}

    [
         'mass_assignment_protection' => true, // default
    ]

    [
        // values could be 'none' | 'fillable' | 'guarded'
        'default_property_assignment' => 'none', // default 
    ]

    [
        'explicity_cast_strings' => false // default
    ]
bash
$ php artisan vendor:publish --provider="JoeCianflone\ModelProperties\ModelPropertiesServiceProvider"