jonnybarnes.uk/app/Models/Contact.php

37 lines
988 B
PHP
Raw Permalink Normal View History

2016-05-19 15:01:28 +01:00
<?php
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;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2016-05-19 15:01:28 +01:00
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
use HasFactory;
2023-02-18 09:34:57 +00:00
/** @var string */
2016-05-19 15:01:28 +01:00
protected $table = 'contacts';
2023-02-18 09:34:57 +00:00
/** @var array<int, string> */
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';
2022-07-09 10:08:26 +01:00
if (array_key_exists('homepage', $this->attributes) && ! empty($this->attributes['homepage'])) {
2022-07-08 16:37:38 +01:00
$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
}