ianvizarra / attendance
Attendance package for Laravel application.
Fund package maintenance!
ianvizarra
www.paypal.me/ianvizarra
Requires
- php: ^8.0|^8.1
- illuminate/contracts: ^9.0
- spatie/enum: ^3.13
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-03-11 12:09:58 UTC
README
Add Attendance feature with ease to your laravel application.
Installation
You can install the package via composer:
composer require ianvizarra/attendance
You can publish and run the migrations with:
php artisan vendor:publish --tag="attendance-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="attendance-config"
This is the contents of the published config file:
return [ 'logs_table' => 'attendance_logs', 'schedule' => [ 'timeIn' => 9, 'timeOut' => 17, 'requiredDailyHours' => 8, 'timeInAllowance' => 30, // minutes 'workDays' => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' ], 'offDays' => [ 'Saturday', 'Sunday' ] ], 'user_model' => config('auth.providers.users.model', \App\Models\User::class), 'users_table' => 'users' ];
Add CanLogAttendance
Interface and HasAttendance
Trait to your User model.
class User extends Authenticatable implements CanLogAttendance { use HasAttendance; }
Usage
Using User Model
$user->attendance(); // HasMany relationship to attendance log model $user->timeIn(); // create an time-in attendance log entry $user->timeOut(); // create an time-out attendance log entry $user->hasTimeIn(); // return true if user already time-in for today $user->hasTimeOut(); // return true if user already time-out for today $user->hasWorked(); // return true if user already time-in and time-out for today $user->getTimeIn(); // return the time-in attendance log for today $user->logAttendance('in', 'on-time', now()); // manually log an attendance by type, status and time
Using Facade
use Ianvizarra\Attendance\Facades\Attendance; // create an attendance log entry for the currently logged-in user // by default it will the current time Attendance::timeIn(); Attendance::timeOut(); // manually set the time logged instead of the current time Attendance::timeIn(now()->subMinutes(30)); // manually set the schedule configuration // the default config values can be found in config/attendance.php `config('attendance.schedule.hours')` Attendance::timeIn(now(), [ 'timeIn' => 8, 'timeOut' => 16, 'requiredDailyHours' => 8 ]); // manually set the user other than the logged-in user Attendance::setUser($user)->timeIn(); // get the time in status Attendance::timeInStatus(); // on-time, late // manually set the time using Carbon instance Attendance::timeInStatus(now()->subMinutes(30)); // on-time, late // manually set the schedule configuration Attendance::timeInStatus(now(), [ 'timeIn' => 8, 'timeOut' => 16, 'requiredDailyHours' => 8 ]); // on-time, late // get the time out status Attendance::timeOutStatus(); // on-time, under-time // manually set the time using Carbon instance Attendance::timeOutStatus(now()->subMinutes(30)); // on-time, under-time // manually set the schedule configuration Attendance::timeOutStatus(now(), [ 'timeIn' => 8, 'timeOut' => 16, 'requiredDailyHours' => 8 ]); // on-time, under-time
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.