chore: init saasshop repo + sql migrations runner + gitee go
This commit is contained in:
49
app/Models/Admin.php
Normal file
49
app/Models/Admin.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Admin extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'name', 'email', 'phone', 'password', 'role', 'status', 'last_login_at',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_login_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function merchantId(): ?int
|
||||
{
|
||||
return $this->merchant_id ? (int) $this->merchant_id : null;
|
||||
}
|
||||
|
||||
public function isPlatformAdmin(): bool
|
||||
{
|
||||
return $this->merchantId() === null;
|
||||
}
|
||||
|
||||
public function isMerchantAdmin(): bool
|
||||
{
|
||||
return $this->merchantId() !== null;
|
||||
}
|
||||
|
||||
public function platformLabel(): string
|
||||
{
|
||||
return $this->isPlatformAdmin() ? 'platform' : 'merchant';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user