40 lines
1.1 KiB
PHP
40 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','last_login_at',
|
|
];
|
|
|
|
protected $hidden = ['password_hash'];
|
|
protected $casts = [
|
|
'is_active'=>'bool',
|
|
'must_change_pw'=>'bool',
|
|
'quota_mb'=>'int',
|
|
'last_login_at'=>'datetime',
|
|
];
|
|
|
|
public function domain(): BelongsTo {
|
|
return $this->belongsTo(Domain::class);
|
|
}
|
|
|
|
// Komfort: Passwort setzen → bcrypt (BLF-CRYPT)
|
|
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 scopeByEmail($q, string $email) { return $q->where('email', $email); }
|
|
|
|
}
|