spyrmp/working-days

v0.0.1 2022-01-03 01:53 UTC

This package is auto-updated.

Last update: 2024-10-29 06:19:41 UTC


README

Laravel plugin for working days.Get working days from the current week. Use custom validation for Date fields.

Install

This project can be installed via Composer run the following command:

composer require spyrmp/working-days

Add the Service Provider & Facade/Alias

Once spyrmp/working-days is installed, you need to register the service provider in config/app.php. Make sure to add the following line above the RouteServiceProvider.

\Spyrmp\WorkingDays\WorkingDayServiceProvider::class,

You may add the following aliases to your config/app.php:

'WorkingDays' => Spyrmp\WorkingDays\Facades\WorkingDays::class,

Publish the package config file by running the following command:

php artisan vendor:publish --provider="Spyrmp\WorkingDays\WorkingDayServiceProvider" --tag="working-days"

Usage

Get working days of the current week

$carbon = Carbon::make('2022-01-03'); // First day of the week
$workingDays = \WorkingDays::getWorkingDays($carbon);
dd($workingDays); // Carbon[]|[]

Get non-working days of the current week

$carbon = Carbon::make('2022-01-03'); // First day of the week
$nonWorkingDays = \WorkingDays::getNonWorkingDays($carbon);
dd($nonWorkingDays); // Carbon[]|[]

###Validation Rules

is_non_working_day

The field under validation must be a value of non-working days. The dates will be passed into the PHP Carbon function in order to be converted into a valid DateTime instance.

is_working_day

The field under validation must be a value of working days. The dates will be passed into the PHP Carbon function in order to be converted into a valid DateTime instance.

$rule= [
       "date1"=>"is_non_working_day"
       "date2"="is_working_day"
];
$inputs = $request->all();
$validation = Validator::make($inputs, $rule);