PHP code example of xisodev / working_hours
1. Go to this page and download the library: Download xisodev/working_hours library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xisodev / working_hours example snippets
\XisoDev\WorkingHours\ScheduleServiceProvider::class,
use XisoDev\WorkingHours\Traits\HasSchedule;
class User extends Model {
use HasSchedule;
...
}
$user->setSchedule([
'monday' => ['08:00-12:00', '13:00-18:00'],
'tuesday' => ['08:00-12:00', '13:00-18:00'],
'wednesday' => ['08:00-12:00', '13:00-18:00'],
'thursday' => ['08:00-12:00', '13:00-18:00'],
'friday' => ['08:00-12:00', '13:00-18:00'],
]);
$user->hasSchedule(); // true
$user->setExclusions([
'03-01' => ['08:00-12:00'],
'12-25' => [],
'12-26' => [],
'2018-05-01' => [],
]);
$user->isAvailableOn('monday'); // true
$user->isAvailableOn('05-28'); // true; This is Monday, in 2018 (current year)
$user->isAvailableOn('2018-05-28'); // true
$user->isAvailableOn(Carbon::create(2018, 5, 28, 0, 0, 0)); // true
$user->isUnavailableOn('monday'); // false
$user->isUnavailableOn('05-28'); // false
$user->isUnavailableOn('2018-05-28'); // false
$user->isUnavailableOn(Carbon::create(2018, 5, 28, 0, 0, 0)); // false
$user->isUnavailableOn('12-25'); // true
$user->isUnavailableOn('03-01'); // false
$user->isAvailableOnAt('monday', '09:00'); // true
$user->isUnavailableOnAt('monday', '09:00'); // false
$user->getHoursOn('03-01'); // 4
$user->getHoursOn('12-26'); // 0
$user->getHoursOn('05-28'); // 9
$user->getHoursOn('2018-05-28'); // 9
$user->getMinutesOn('03-01'); // 240
$user->deleteSchedule();
$user->hasSchedule(); // false
bash
$ php artisan vendor:publish --provider="XisoDev\WorkingHours\ScheduleServiceProvider"
bash
$ php artisan migrate