Files
CRM/app/Models/Contact/ContactField.php
Kroonk a213a1dba0
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
refactor: replace custom CRM with Monica fork
2026-05-22 16:19:55 +02:00

96 lines
2.2 KiB
PHP

<?php
namespace App\Models\Contact;
use App\Traits\HasUuid;
use App\Models\Account\Account;
use App\Interfaces\LabelInterface;
use App\Models\ModelBindingWithContact as Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class ContactField extends Model implements LabelInterface
{
use HasUuid;
/**
* The attributes that aren't mass assignable.
*
* @var array<string>|bool
*/
protected $guarded = ['id'];
/**
* All of the relationships to be touched.
*
* @var array
*/
protected $touches = ['contact'];
/**
* Get the account record associated with the contact field.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo(Account::class);
}
/**
* Get the contact record associated with the contact field.
*
* @return BelongsTo
*/
public function contact()
{
return $this->belongsTo(Contact::class);
}
/**
* Get the label associated with the contact.
*
* @return BelongsToMany
*/
public function labels()
{
return $this->belongsToMany(ContactFieldLabel::class);
}
/**
* Get the type associated with the contact field.
*
* @return BelongsTo
*/
public function contactFieldType()
{
return $this->belongsTo(ContactFieldType::class);
}
/**
* Scope a query to only include contact field of email type.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeEmail($query)
{
return $query->whereHas('contactFieldType', function ($query) {
$query->where('type', '=', ContactFieldType::EMAIL);
});
}
/**
* Scope a query to only include contact field of phone type.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePhone($query)
{
return $query->whereHas('contactFieldType', function ($query) {
$query->where('type', '=', ContactFieldType::PHONE);
});
}
}