searchable; } public static function boot() { parent::boot(); static::creating(function ($model) { $model->person_type = static::$type; $model->hash = md5(time().wp_generate_uuid4()); }); static::addGlobalScope(function ($builder) { $builder->where('person_type', 'agent'); }); } /** * One2Many: Customer has to many Click Tickets * @return Model Collection */ public function tickets() { $foreign_key = self::$type . '_id'; $class = __NAMESPACE__ . '\Ticket'; return $this->hasMany( $class, $foreign_key, 'id' ); } public function groups() { return $this->belongsToMany( AgentGroup::class, 'fs_tag_pivot', 'source_id', 'tag_id' )->wherePivot('source_type', 'agent_group'); } public function scopeMentionBy($query, $search) { if (!$search) { return $query; } return $query->where(function ($q) use ($search) { $q->where('first_name', 'LIKE', '%' . $search . '%') ->orWhere('last_name', 'LIKE', '%' . $search . '%') ->orWhere('email', 'LIKE', '%' . $search . '%'); }); } }