This repository has been archived on 2025-12-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Caramel-CRM-Backup/app/Models/Contact.php
T
vollstock 8703e5ff40
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
Add initial Code
2025-10-20 08:57:51 +02:00

49 lines
944 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
use HasFactory;
protected $fillable = [
'customer_id',
'first_name',
'last_name',
'email',
'phone',
'position',
'is_primary',
'avatar',
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
/**
* Get the URL to the contact's avatar.
*/
public function getAvatarUrlAttribute()
{
if ($this->avatar) {
return asset('storage/' . $this->avatar);
}
// Return null if no avatar is set
return null;
}
/**
* Scope a query to order contacts with primary contacts first.
*/
public function scopePrimaryFirst($query)
{
return $query->orderBy('is_primary', 'desc');
}
}