Skip to content

Instantly share code, notes, and snippets.

@MACscr
Created August 17, 2022 01:02
Show Gist options
  • Save MACscr/fedae61ea3f6f6498b541b7ad8232762 to your computer and use it in GitHub Desktop.
Save MACscr/fedae61ea3f6f6498b541b7ad8232762 to your computer and use it in GitHub Desktop.
Laravel Component for Filament Curator Images. Accessed by GeneralSettings (spatie settings) or Curator Pubic Id
<img src="{{ $image->url }}" class="{{ $class }}" alt="{{ $image->alt }}" title="{{ $image->title }}" @if($image->height)height="{{ $image->height }}px" width="{{ $image->width }}px"@endif />
<?php
namespace App\View\Components;
use App\Settings\GeneralSettings;
use FilamentCurator\Models\Media;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\View\Component;
class CuratorImage extends Component
{
public mixed $class;
public Model $image;
/**
* Create a new component instance.
*
* @param mixed $class
* @param null $publicId
* @param null $setting
*/
public function __construct(mixed $class, $publicId = null, $setting = null)
{
if ($setting) {
$id = app(GeneralSettings::class)->$setting;
$this->image = Media::query()->where('id',$id)->first();
}else{
$this->image = Media::query()->where('public_id',$publicId)->first();
}
$this->class = $class ?? 'inline-block';
}
/**
* Get the view / contents that represent the component.
*
* @return View
*/
public function render(): View
{
return view('components.curator-image');
}
}
#example usage
<x-curator-image setting="dark_logo" class="hidden sm:block h-8 w-auto sm:h-10" />
<x-curator-image publicId="media/industry-directory" class="w-full rounded-xl shadow-xl ring-1 ring-black ring-opacity-5 lg:absolute lg:left-0 lg:h-full lg:w-auto lg:max-w-none" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment