52 lines
996 B
PHP
52 lines
996 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Orders;
|
||
|
|
|
||
|
|
use App\Traits\BelongsToTenant;
|
||
|
|
use App\Traits\ModelTrait;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class Client extends Model
|
||
|
|
{
|
||
|
|
use BelongsToTenant, ModelTrait;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'tenant_id',
|
||
|
|
'client_group_id',
|
||
|
|
'client_code',
|
||
|
|
'name',
|
||
|
|
'contact_person',
|
||
|
|
'phone',
|
||
|
|
'email',
|
||
|
|
'address',
|
||
|
|
'is_active',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
// ClientGroup 관계
|
||
|
|
public function clientGroup()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(ClientGroup::class, 'client_group_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Orders 관계
|
||
|
|
public function orders()
|
||
|
|
{
|
||
|
|
return $this->hasMany(Order::class, 'client_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 스코프
|
||
|
|
public function scopeActive($query)
|
||
|
|
{
|
||
|
|
return $query->where('is_active', 'Y');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeCode($query, string $code)
|
||
|
|
{
|
||
|
|
return $query->where('client_code', $code);
|
||
|
|
}
|
||
|
|
}
|