Add initial Code
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user