spatie/laravel-dashboard-coffee-tile
Laravel Dashboard tile that displays coffee brewing stats. Publish migrations, add the Livewire coffee-tile component, then post brew events to the included CoffeeController endpoint (auth up to you). Supports an optional total offset for existing counts.
Installation:
composer require spatie/laravel-dashboard-coffee-tile
Publish the config (if needed):
php artisan vendor:publish --provider="Spatie\DashboardCoffeeTile\DashboardCoffeeTileServiceProvider"
Register the Tile:
Add the tile to your Laravel Dashboard configuration (e.g., config/dashboard.php):
'tiles' => [
\Spatie\DashboardCoffeeTile\DashboardCoffeeTile::class,
],
First Use Case:
Data Collection:
POST /api/coffee-events) or a queue job for async processing.// routes/api.php
Route::post('/coffee-events', [CoffeeEventController::class, 'store']);
Dashboard Tile Customization:
namespace App\Dashboard;
use Spatie\DashboardCoffeeTile\DashboardCoffeeTile as BaseTile;
class CustomCoffeeTile extends BaseTile
{
public function getCoffeeStats()
{
// Custom logic to fetch/process data
return [
'totalCups' => CoffeeEvent::count(),
'todayCups' => CoffeeEvent::today()->count(),
];
}
}
config/dashboard.php.Real-Time Updates:
// Event: CoffeeEventCreated
class CoffeeEventCreated implements ShouldBroadcast
{
public function broadcastOn()
{
return new Channel('coffee-stats');
}
}
Testing:
$response = $this->postJson('/api/coffee-events', ['cups' => 2]);
$response->assertCreated();
Listener Dependency:
/api/coffee-listener/health) to verify the listener’s status.Data Persistence:
coffee_events table). If not, create a migration:
php artisan make:migration create_coffee_events_table
Schema::create('coffee_events', function (Blueprint $table) {
$table->id();
$table->integer('cups');
$table->timestamps();
});
Rate Limiting:
Route::middleware(['throttle:60,1'])->post('/api/coffee-events', ...);
Logs:
config/dashboard-coffee-tile.php:
'log_events' => env('COFFEE_TILE_LOG_EVENTS', false),
storage/logs/laravel.log) for listener request failures.Network Issues:
Custom Metrics:
getCoffeeStats():
public function getCoffeeStats()
{
return [
'totalCups' => CoffeeEvent::count(),
'avgCupsPerHour' => CoffeeEvent::avgCupsPerHour(), // Custom query
];
}
Visual Customization:
resources/views/vendor/dashboard-coffee-tile/tile.blade.php) to change colors, charts, or layout.Multi-Machine Support:
machine_id to coffee_events and filtering in getCoffeeStats():
CoffeeEvent::where('machine_id', $machineId)->count();
How can I help you explore Laravel packages today?