spatie/laravel-dashboard-time-weather-tile
Time & Weather Tile for Spatie Laravel Dashboard. Shows the current time and local weather on your dashboard, with simple setup and configuration. Ideal for wall-mounted displays and status screens.
composer require spatie/laravel-dashboard-time-weather-tile
php artisan vendor:publish --provider="Spatie\DashboardTimeWeatherTile\DashboardTimeWeatherTileServiceProvider"
config/dashboard.php):
'tiles' => [
\Spatie\DashboardTimeWeatherTile\DashboardTimeWeatherTile::class,
],
.env:
WEATHER_API_KEY=your_api_key_here
WEATHER_API_UNITS=metric # or imperial
<x-dashboard-tile :tile="$dashboardTimeWeatherTile" />
Display a time and weather tile in your Laravel Dashboard for internal tools or admin panels. Example:
// In a controller or service
use Spatie\DashboardTimeWeatherTile\DashboardTimeWeatherTile;
public function showDashboard()
{
$tile = new DashboardTimeWeatherTile(
timezone: config('app.timezone'),
weatherApiKey: config('services.openweathermap.api_key'),
location: 'New York' // Optional: Override default location
);
return view('dashboard', ['dashboardTimeWeatherTile' => $tile]);
}
Basic Integration:
config/app.timezone, weather from OpenWeatherMap).$tile = new DashboardTimeWeatherTile();
Custom Location:
$tile = new DashboardTimeWeatherTile(location: 'London,UK');
Units Configuration:
$tile = new DashboardTimeWeatherTile(units: 'imperial');
config/dashboard-time-weather-tile.php:
'units' => 'metric',
Caching:
Spatie\DashboardTimeWeatherTile\WeatherService to customize caching logic.Blade Integration:
<x-dashboard-time-weather-tile :tile="$dashboardTimeWeatherTile" />
{!! $dashboardTimeWeatherTile->render() !!}
Dynamic Timezone:
$tile = new DashboardTimeWeatherTile(timezone: auth()->user()->timezone);
Weather Provider Swap:
WeatherService to support alternative APIs (e.g., Buienradar):
use Spatie\DashboardTimeWeatherTile\WeatherService;
class CustomWeatherService extends WeatherService
{
public function getWeatherData(string $location): array
{
// Custom logic for Buienradar or other APIs
}
}
$this->app->bind(
\Spatie\DashboardTimeWeatherTile\WeatherService::class,
CustomWeatherService::class
);
Conditional Rendering:
$tile = new DashboardTimeWeatherTile(showWeather: env('SHOW_WEATHER', true));
Testing:
WeatherService in tests:
$weatherService = Mockery::mock(WeatherService::class);
$weatherService->shouldReceive('getWeatherData')
->andReturn(['temp' => 20, 'description' => 'Clear']);
$tile = new DashboardTimeWeatherTile(weatherService: $weatherService);
Timezone Mismatch:
config/app.timezone is not set correctly.APP_TIMEZONE in .env is accurate (e.g., America/New_York). Release 4.1.0 resolves this by using the configured timezone automatically.Weather API Failures:
showWeather flag to disable weather display:
$tile = new DashboardTimeWeatherTile(showWeather: false);
WeatherService to handle errors gracefully.Caching Issues:
config/dashboard-time-weather-tile.php:
'cache_ttl_minutes' => 5,
Location Ambiguity:
Paris,FR) or implement a location resolver.CSS Conflicts:
.dashboard-time-weather-tile {
/* Custom styles */
}
Log Weather Data:
$weatherService = app(WeatherService::class);
$data = $weatherService->getWeatherData('New York');
\Log::info('Weather Data:', $data);
Check API Key:
WEATHER_API_KEY in .env is correct and not expired.Test Timezone:
.env:
APP_TIMEZONE=America/New_York
Disable Weather:
$tile = new DashboardTimeWeatherTile(showWeather: false);
Custom Weather Icons:
@extends('dashboard-time-weather-tile::tile')
@section('weather-icon')
@if($weather['description'] === 'Clear')
<i class="fas fa-sun"></i>
@endif
@endsection
Add Forecast:
WeatherService to fetch forecast data:
public function getForecastData(string $location): array
{
// Implement logic for 5-day forecast
}
Localization:
$tile = new DashboardTimeWeatherTile(locale: 'fr_FR');
Dark Mode Support:
$tile->addClass('dark:bg-gray-800');
Event Listeners:
\Event::listen(
\Spatie\DashboardTimeWeatherTile\Events\WeatherUpdated::class,
function ($event) {
\Log::info('Weather updated:', $event->data);
}
);
How can I help you explore Laravel packages today?