fanatic/app/Traits/Imageable.php

30 lines
611 B
PHP
Raw Normal View History

2022-04-26 18:43:36 -07:00
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Storage;
trait Imageable
{
public static function imagePath($image) : ?string
{
2022-04-28 12:01:17 -07:00
$path = strtolower(substr(strrchr(__CLASS__, '\\'), 1));
2022-04-26 18:43:36 -07:00
if (isset($image)) {
2022-04-28 12:01:17 -07:00
return $image->storePublicly($path, 'public');
2022-04-26 18:43:36 -07:00
} else {
return null;
}
}
public function updateImage($image) : ?string
{
if (isset($this->image) && isset($image)) {
Storage::delete($this->image);
self::imagePath($image);
} else {
return null;
}
}
}