mailwolt/app/Models/MailUser.php

43 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class MailUser extends Model
{
// protected $table = 'mail_users';
protected $fillable = [
'domain_id','localpart','email','password_hash',
'is_active','must_change_pw','quota_mb','is_system'
];
protected $hidden = ['password_hash'];
protected $casts = [
'is_active'=>'bool',
'is_system' => 'boolean',
'must_change_pw'=>'bool',
'quota_mb'=>'int',
'last_login_at'=>'datetime',
];
public function domain(): BelongsTo {
return $this->belongsTo(Domain::class);
}
public function setPasswordAttribute(string $plain): void {
// optional: allow 'password' virtual attribute
$this->attributes['password_hash'] = password_hash($plain, PASSWORD_BCRYPT);
}
// Scopes
public function scopeActive($q) { return $q->where('is_active', true); }
public function scopeSystem($q) { return $q->where('is_system', true); }
public function scopeByEmail($q, string $email) { return $q->where('email', $email); }
}