1. Go to this page and download the library: Download konnco/filament-timematrix 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/ */
konnco / filament-timematrix example snippets
use Konnco\FilamentTimeMatrix\Forms\TimeMatrix;
TimeMatrix::make('schedule')
->label('Select Schedule')
->
use Konnco\FilamentTimeMatrix\Forms\TimeMatrix;
use Konnco\FilamentTimeMatrix\Enums\Day;
use Carbon\CarbonInterface;
TimeMatrix::make('schedule')
->label('Select Schedule')
->default range from 9 AM - 5 PM
->businessHours()
# Set specific days using Day enum
->days([
Day::MONDAY,
Day::TUESDAY,
Day::WEDNESDAY,
])
# OR use Carbon constants
->days([
CarbonInterface::MONDAY,
CarbonInterface::SATURDAY,
])
# OR use helper methods
->weekdays() # Monday - Friday only
->weekend() # Saturday - Sunday only
# Set locale and format
->locale('id', 'long') # long: Monday, short: Mon,
->locale('en', 'short')
# Toggle select all buttons
->showSelectAllHours(false)
->showSelectAllDays(false)
->columnSpanFull();
use Konnco\FilamentTimeMatrix\Infolists\TimeMatrix;
TimeMatrix::make('schedule')
->label('Schedule')
->columnSpanFull();
use Konnco\FilamentTimeMatrix\Infolists\TimeMatrix;
use Konnco\FilamentTimeMatrix\Enums\Day;
TimeMatrix::make('operational_hour')
->label('Operational Hours')
# Match the hour range used on the form
->hours(startTime: 9, endTime: 17) # OR ->businessHours()
# Match the days used on the form
->days([Day::MONDAY, Day::FRIDAY]) # OR ->weekdays() / ->weekend()
# Set locale and format (long/short)
->locale('id', 'long')
->columnSpanFull();
use Konnco\FilamentTimeMatrix\Facades\TimeMatrix;
use Carbon\Carbon;
$data = ['monday' => [8 => true, 9 => true]];
# Check if active right now
TimeMatrix::isActiveAt($data);
# Check if active at specific time
TimeMatrix::isActiveAt($data, Carbon::parse('next monday 8:00')); # true
TimeMatrix::isActiveAt($data, Carbon::tomorrow()->setTime(14, 0)); # true/false
# Check if active 2 hours from now
TimeMatrix::isActiveAt($data, now()->addHours(2));
use Konnco\FilamentTimeMatrix\Enums\Day;
use Carbon\Carbon;
$data = [
'monday' => [8 => true],
'tuesday' => [14 => true],
];
# Check if active today (no parameter needed!)
TimeMatrix::hasActiveDay($data); # true/false
# Check specific days
TimeMatrix::hasActiveDay($data, Day::MONDAY);
TimeMatrix::hasActiveDay($data, 'tuesday');
TimeMatrix::hasActiveDay($data, Day::WEDNESDAY);
# Check tomorrow
TimeMatrix::hasActiveDay($data, Day::fromCarbon(Carbon::tomorrow()));
use Konnco\FilamentTimeMatrix\Enums\Day;
$data = [
'monday' => [8 => true, 9 => true, 14 => true],
'tuesday' => [10 => true, 11 => true],
];
# Get today's active hours
TimeMatrix::getActiveHours($data); # [8, 9, 14]
# Get specific day's hours
TimeMatrix::getActiveHours($data, Day::MONDAY); # [8, 9, 14]
TimeMatrix::getActiveHours($data, 'tuesday'); # [10, 11]
# Get tomorrow's hours
TimeMatrix::getActiveHours($data, Day::fromCarbon(Carbon::tomorrow()));
# Loop through today's hours
foreach (TimeMatrix::getActiveHours($data) as $hour) {
echo sprintf('%02d:00 - Available', $hour);
}
use Konnco\FilamentTimeMatrix\Facades\TimeMatrix;
class StoreService
{
public function getOpenStores()
{
return Store::all()->filter(function ($store$) {
# No parameter = check now!
return TimeMatrix::isActiveAt($store$->operational_hours);
});
}
public function countOpenNow(): int
{
return Store::get()->filter(fn($store) =>
TimeMatrix::isActiveAt($store->operational_hours)
)->count();
}
public function getOpenTomorrow()
{
return Store::get()->filter(fn($store) =>
TimeMatrix::hasActiveDay(
$store->operational_hours,
Day::fromCarbon(Carbon::tomorrow())
)
);
}
}