client api
This commit is contained in:
+63
-7
@@ -2,19 +2,28 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class Customer extends Authenticatable
|
||||
{
|
||||
use HasFactory, HasApiTokens;
|
||||
use HasFactory, HasApiTokens, HasUuids;
|
||||
|
||||
protected $table = 'customer';
|
||||
protected $table = 'customers';
|
||||
|
||||
/**
|
||||
* Chỉ định cột sẽ nhận UUID.
|
||||
* Mặc định HasUuids dùng cột 'id', mình đổi sang 'uuid'.
|
||||
*/
|
||||
public function uniqueIds()
|
||||
{
|
||||
return ['uuid'];
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
'fullname',
|
||||
'avatar',
|
||||
'address',
|
||||
'state',
|
||||
@@ -28,15 +37,26 @@ class Customer extends Authenticatable
|
||||
'email_hash',
|
||||
'email_marketing',
|
||||
'receive_deposit',
|
||||
'cccd',
|
||||
'front_cccd',
|
||||
'back_cccd',
|
||||
'identity_number',
|
||||
'front_identity_number',
|
||||
'back_identity_number',
|
||||
'password',
|
||||
'credit',
|
||||
'total',
|
||||
'remember_token',
|
||||
'status',
|
||||
'gender',
|
||||
'province_code',
|
||||
'ward_code',
|
||||
];
|
||||
|
||||
/**
|
||||
* Appends for API
|
||||
*/
|
||||
protected $appends = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'point',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -163,4 +183,40 @@ class Customer extends Authenticatable
|
||||
{
|
||||
return (bool) $this->receive_deposit;
|
||||
}
|
||||
|
||||
|
||||
public function getPointAttribute()
|
||||
{
|
||||
return (string) floor($this->total / 100);
|
||||
}
|
||||
|
||||
public function getCmndBeforeAttribute()
|
||||
{
|
||||
return $this->front_identity_number ?? '';
|
||||
}
|
||||
|
||||
public function getCmndAfterAttribute()
|
||||
{
|
||||
return $this->back_identity_number ?? '';
|
||||
}
|
||||
|
||||
public function getCmndAttribute()
|
||||
{
|
||||
return $this->identity_number;
|
||||
}
|
||||
|
||||
public function getOffMailMarketingAttribute()
|
||||
{
|
||||
return $this->email_marketing;
|
||||
}
|
||||
|
||||
public function province()
|
||||
{
|
||||
return $this->belongsTo(Province::class, 'province_code', 'code');
|
||||
}
|
||||
|
||||
public function ward()
|
||||
{
|
||||
return $this->belongsTo(Ward::class, 'ward_code', 'code');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user