2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
namespace App\Models;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2022-07-08 16:37:38 +01:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2021-08-31 12:28:00 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Contact extends Model
|
|
|
|
{
|
2021-08-31 12:28:00 +01:00
|
|
|
use HasFactory;
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
/**
|
|
|
|
* The database table used by the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'contacts';
|
|
|
|
|
|
|
|
/**
|
2017-07-17 17:07:08 +01:00
|
|
|
* We shall guard against mass-migration.
|
2016-05-19 15:01:28 +01:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-07-17 17:07:08 +01:00
|
|
|
protected $fillable = ['nick', 'name', 'homepage', 'twitter', 'facebook'];
|
2022-07-08 16:37:38 +01:00
|
|
|
|
|
|
|
protected function photo(): Attribute
|
|
|
|
{
|
|
|
|
$photo = '/assets/profile-images/default-image';
|
|
|
|
|
|
|
|
if (array_key_exists('homepage', $this->attributes) && !empty($this->attributes['homepage'])) {
|
|
|
|
$host = parse_url($this->attributes['homepage'], PHP_URL_HOST);
|
|
|
|
if (file_exists(public_path() . '/assets/profile-images/' . $host . '/image')) {
|
|
|
|
$photo = '/assets/profile-images/' . $host . '/image';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Attribute::make(
|
|
|
|
get: fn () => $photo,
|
|
|
|
);
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|