| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Models; |
| 4 |
|
| 5 |
|
| 6 |
class Agent extends Person |
| 7 |
{ |
| 8 |
protected static $type = 'agent'; |
| 9 |
|
| 10 |
protected $searchable = [ |
| 11 |
'id', |
| 12 |
'first_name', |
| 13 |
'last_name', |
| 14 |
'email', |
| 15 |
'address_line_1', |
| 16 |
'address_line_2', |
| 17 |
'country' |
| 18 |
]; |
| 19 |
|
| 20 |
public static function boot() |
| 21 |
{ |
| 22 |
static::creating(function ($model) { |
| 23 |
$model->person_type = static::$type; |
| 24 |
$model->hash = md5(time().wp_generate_uuid4()); |
| 25 |
}); |
| 26 |
|
| 27 |
static::addGlobalScope(function ($builder) { |
| 28 |
$builder->where('person_type', 'agent'); |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* One2Many: Customer has to many Click Tickets |
| 35 |
* @return Model Collection |
| 36 |
*/ |
| 37 |
public function tickets() |
| 38 |
{ |
| 39 |
$foreign_key = self::$type . '_id'; |
| 40 |
|
| 41 |
$class = __NAMESPACE__ . '\Ticket'; |
| 42 |
|
| 43 |
return $this->hasMany( |
| 44 |
$class, $foreign_key, 'id' |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|