PHP code example of joemugen / eloquenty-model

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

    

joemugen / eloquenty-model example snippets



use JoeMugen\EloquentyModel\Model;

class User extends Model {
    protected $hidden = ['password'];
    protected $guarded = ['password'];
    protected $casts = ['age' => 'integer'];

    public function save()
    {
        return API::post('/items', $this->attributes);
    }

    public function setBirthdayAttribute($value)
    {
        $this->attributes['birthday'] = strtotime($value);
    }

    public function getBirthdayAttribute($value)
    {
        return new DateTime("@$value");
    }

    public function getAgeAttribute($value)
    {
        return $this->birthday->diff(new DateTime('now'))->y;
    }
}

$item = new User(['name' => 'John']);
$item->password = 'secret';

echo $item; // {"name":"John"}