refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
95
app/Models/Contact/ContactField.php
Normal file
95
app/Models/Contact/ContactField.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user