You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
<?php
|
|
|
|
namespace Modules\Agents\Entities;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class Customer extends Model
|
|
{
|
|
use HasFactory, \Illuminate\Database\Eloquent\SoftDeletes;
|
|
protected $table = 'se_customers';
|
|
protected $fillable = ['id', 'name', 'phone', 'email', 'grade', 'msg', 'agent_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'deleted_at'];
|
|
protected $dates = ['deleted_at'];
|
|
|
|
// protected static function newFactory()
|
|
// {
|
|
// return \Modules\Agents\Database\factories\CustomerFactory::new();
|
|
// }
|
|
|
|
/**
|
|
* Summary of scopeByPhone
|
|
* @param mixed $query
|
|
* @param mixed $phone
|
|
* @return mixed
|
|
*/
|
|
public function scopeByPhone($query, $phone)
|
|
{
|
|
return $query->where('phone', $phone);
|
|
}
|
|
/**
|
|
* Summary of scopeNotAgent
|
|
* @param mixed $query
|
|
* @param mixed $agentId
|
|
* @return mixed
|
|
*/
|
|
public function scopeNotAgent($query, $agentId)
|
|
{
|
|
return $query->where('agent_id', '<>', $agentId);
|
|
}
|
|
/**
|
|
* Summary of scopeInAgent
|
|
* @param mixed $query
|
|
* @param mixed $agentId
|
|
* @return mixed
|
|
* **/
|
|
public function scopeInAgent($query, $agentId)
|
|
{
|
|
return $query->where('agent_id', '=', $agentId);
|
|
}
|
|
public function scopeSearch($query, $searchKey)
|
|
{
|
|
return $query->where(function ($query) use ($searchKey) {
|
|
$query->where('name', 'LIKE', '%' . $searchKey . '%')
|
|
->orWhere('phone', 'LIKE', '%' . $searchKey . '%')
|
|
->orWhere('email', 'LIKE', '%' . $searchKey . '%');
|
|
});
|
|
}
|
|
}
|
|
|