jonnybarnes.uk/app/Models/Contact.php

34 lines
995 B
PHP
Raw 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
2026-04-07 09:01:19 +01:00
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Table;
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;
2026-04-07 09:01:19 +01:00
#[Table('contacts')]
#[Fillable(['nick', 'name', 'homepage', 'twitter', 'facebook'])]
2016-05-19 15:01:28 +01:00
class Contact extends Model
{
use HasFactory;
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);
2026-04-07 09:01:19 +01:00
if (file_exists(public_path().'/assets/profile-images/'.$host.'/image')) {
$photo = '/assets/profile-images/'.$host.'/image';
2022-07-08 16:37:38 +01:00
}
}
return Attribute::make(
get: fn () => $photo,
);
}
2016-05-19 15:01:28 +01:00
}