b2in/app/View/Components/WebPicture.php
2026-04-10 17:18:17 +02:00

34 lines
776 B
PHP

<?php
declare(strict_types=1);
namespace App\View\Components;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class WebPicture extends Component
{
public string $webpSrc;
public bool $hasWebp;
public function __construct(
public string $src,
public string $alt = '',
public string $class = '',
public string $loading = 'lazy',
public string $width = '',
public string $height = '',
) {
$this->webpSrc = preg_replace('/\.(jpe?g|png)$/i', '.webp', $this->src);
$this->hasWebp = file_exists(public_path(
str_replace(asset(''), '', $this->webpSrc)
));
}
public function render(): View
{
return view('components.web-picture');
}
}