Modelロード値保存付与操作

4128 ワード



namespace App\Models;

use function GuzzleHttp\Psr7\str;
use Illuminate\Database\Eloquent\Model;

class Users extends Model
{
    protected $table = 'users';


    public function getDueTimeAttribute($value)
    {
        if ($value == 0)
            return $this->attributes['due_time'] = now();
        else
            return $this->attributes['due_time'] = date('Y-m-d h:i:s', $value);
    }

    public function setDueTimeAttribute($value)
    {
        $this->attributes['due_time'] = strtotime($value);

    }

}