Skip to content

Instantly share code, notes, and snippets.

@AnandPilania
Created December 8, 2023 11:07
Show Gist options
  • Save AnandPilania/7fdde2f9e9bf0c7134a390d8eeaf5021 to your computer and use it in GitHub Desktop.
Save AnandPilania/7fdde2f9e9bf0c7134a390d8eeaf5021 to your computer and use it in GitHub Desktop.
Laravel: Pulse sample card - Inspire

Add the card to dashboard

<livewire:pulse-cards.inspire-card cols="3" />
<?php
declare(strict_types=1);
namespace App\Livewire\PulseCards;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View as ViewFacade;
use Laravel\Pulse\Livewire\Card;
use Livewire\Attributes\Lazy;
use Throwable;
#[Lazy]
class InspireCard extends Card
{
public const CACHE_KEY = 'inspire_card_result';
public function render(): View
{
try {
$message = Cache::remember(self::CACHE_KEY, 300, static fn () => Inspiring::quote());
} catch (Throwable $th) {
Cache::forget(self::CACHE_KEY);
$message = $th->getMessage();
}
return ViewFacade::make('livewire.pulse-cards.inspire-card', [
'message' => $message,
]);
}
}
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
<x-pulse::card-header
name="Inspire"
title="AAA"
>
<x-slot:icon>
<x-pulse::icons.moon />
</x-slot:icon>
</x-pulse::card-header>
<x-pulse::scroll :expand="$expand" wire:poll.300s>
<div class="h-full flex flex-col items-center justify-center p-4">
<blockquote class="italic text-md text-gray-400 dark:text-gray-600">
{!! $message !!}
</blockquote>
</div>
</x-pulse::scroll>
</x-pulse::card>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment