spatie/laravel-dashboard-attendances-tile
Spatie tile for Laravel Dashboard that shows office attendance at a glance—who’s in the office and who’s not. Built to plug into Laravel Dashboard and display current team presence in a simple, readable tile.
Installation:
composer require spatie/laravel-dashboard-attendances-tile
Ensure laravel-dashboard is installed (this package is a tile for it).
Publish Config (if needed):
php artisan vendor:publish --provider="Spatie\DashboardAttendancesTile\DashboardAttendancesTileServiceProvider"
(Note: The package is minimal; config is rarely needed for basic use.)
Register the Tile:
Add the tile to your dashboard in app/Providers/DashboardServiceProvider.php:
public function boot()
{
Dashboard::create()
->row()
->tile(Spatie\DashboardAttendancesTile\DashboardAttendancesTile::class)
->endRow();
}
First Use Case:
Visit your dashboard (/dashboard). The tile will display users marked as "present" (based on is_present column in your users table by default).
Data Source:
The tile queries the users table for records with is_present = true (configurable via present_column in config).
Override the default behavior by extending the tile:
use Spatie\DashboardAttendancesTile\DashboardAttendancesTile;
class CustomAttendancesTile extends DashboardAttendancesTile
{
protected function getPresentUsers()
{
return User::where('custom_status', 'active')->get();
}
}
Styling/Customization:
present_color and absent_color in config (e.g., #4CAF50 for present, #F44336 for absent).getPresentLabel() and getAbsentLabel() in a custom tile class.Integration with Auth: Exclude admins or specific roles from attendance checks:
protected function getPresentUsers()
{
return auth()->user()->isAdmin()
? User::none()
: User::where('is_present', true)->get();
}
Real-Time Updates: Use Laravel Echo/Pusher to update the tile dynamically when attendance changes:
// Frontend (dashboard JS)
Echo.channel('attendance-updates')
.listen('AttendanceUpdated', (e) => {
location.reload(); // Or fetch new data via AJAX
});
Default Column Assumption:
The tile assumes a is_present boolean column. If your schema differs (e.g., status = 'present'), extend the tile or publish/config the present_column:
// config/dashboard-attendances-tile.php
'present_column' => 'status',
'present_value' => 'present',
Performance:
Avoid eager-loading heavy relationships in getPresentUsers(). Use select() to limit columns:
return User::where('is_present', true)->select('id', 'name')->get();
Caching: The tile doesn’t cache by default. For large teams, cache the query result:
protected function getPresentUsers()
{
return Cache::remember('present_users', now()->addHours(1), function () {
return User::where('is_present', true)->get();
});
}
Blank Tile?:
Check if the users table has records with is_present = true. Add a dd() in getPresentUsers() to verify data.
dd(User::where('is_present', true)->get()); // Debug query
Styling Issues:
Inspect the tile’s Blade template (resources/views/vendor/dashboard-attendances-tile.blade.php) if CSS isn’t applying. Override it by publishing the view:
php artisan vendor:publish --tag=dashboard-attendances-tile-views
Custom User Model:
Bind the tile to a custom model (e.g., Employee):
class CustomAttendancesTile extends DashboardAttendancesTile
{
protected $model = \App\Models\Employee::class;
}
Multi-Location Support:
Add a location column and filter by office:
protected function getPresentUsers()
{
return User::where('is_present', true)
->where('office_id', request('office_id'))
->get();
}
Webhook Triggers: Sync attendance data via webhooks (e.g., from a badge system):
// Route webhook to update attendance
Route::post('/update-attendance', function (Request $request) {
$user = User::find($request->user_id);
$user->update(['is_present' => $request->status]);
});
How can I help you explore Laravel packages today?