1. Go to this page and download the library: Download free3_5man/laravel-macros library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// if request field equals to db field
$whereFields = [
'users' => [
'name',
'birthday',
],
];
$data = [
'name' => 'michael',
'birthday' => '2020-02-01',
];
// the param '$data' retrieve request input default if not passed
User::query()->filter($whereFields, $useWhereIn = false, $data)->count(); // 1// if request field doesn't equal to db field
$whereFields = [
'users' => [
'name' => 'name_field_in_request_query',
'birthday' => 'birthday_field_in_request_query',
],
];
$data = [
'name_field_in_request_query' => 'michael',
'birthday_field_in_request_query' => '2020-02-01',
];
// the param '$data' retrieve request input default if not passed
User::query()->filter($whereFields, $useWhereIn = false, $data)->count(); // 1// use whereIn for each field
$whereFields = [
'users' => [
'name',
'birthday',
],
];
$data = [
'name' => [
'freeman',
'michael',
],
'birthday' => [
'2020-02-01',
],
];
// the param '$data' retrieve request input default if not passed
User::query()->filter($whereFields, $useWhereIn = true, $data)->count(); // 1
// if request field equals to db field
$whereFields = [
'users' => [
'height',
],
];
$data = [
'height_begin' => 170,
'height_end' => 180,
];
// the param '$data' retrieve request input default if not passed
User::query()->filterRange($whereFields, $useWhereDate = false, $data)->count(); // 1// if request field doesn't equal to db field
$whereFields = [
'users' => [
'height' => 'height_field_in_request_query',
],
];
$data = [
'height_field_in_request_query_begin' => 170,
'height_field_in_request_query_end' => 180,
];
// the param '$data' retrieve request input default if not passed
User::query()->filterRange($whereFields, $useWhereDate = false, $data)->count(); // 1// use whereDate for each field
$whereFields = [
'users' => [
'birthday',
],
];
$data = [
'birthday_begin' => '2020-01-15',
'birthday_end' => '2020-02-15',
];
// the param '$data' retrieve request input default if not passed
User::query()->filterRange($whereFields, $useWhereDate = true, $data)->count(); // 1// specify the suffix to replace default _begin and _end
$whereFields = [
'users' => [
'birthday',
],
];
$data = [
'birthday_start' => '2020-01-15',
'birthday_finish' => '2020-02-15',
];
// the param '$data' retrieve request input default if not passed
$builder->filterRange($whereFields, $useWhereDate = true, $data, '_start', '_finish')->count(); // 1
// if request field equals to db field
$whereFields = [
'users' => [
'email',
],
];
$data = [
'email' => null,
];
// the param '$data' retrieve request input default if not passed
User::query()->filterWhereNull($whereFields, $data)->count(); // 2// if request field doesn't equal to db field
$whereFields = [
'users' => [
'email' => 'email_field_in_request_query',
],
];
$data = [
'email_field_in_request_query' => null,
];
// the param '$data' retrieve request input default if not passed
$builder->filterWhereNull($whereFields, $data)->count(); // 2
(new CarbonPeriod('2021-07-31', '2021-08-01'))->countWeeks(); // 1
(new CarbonPeriod('2021-08-01', '2021-08-01'))->countWeeks(); // 1
(new CarbonPeriod('2021-08-01', '2021-08-02'))->countWeeks(); // 2
(new CarbonPeriod('2021-08-02', '2021-08-01'))->countWeeks(); // 2
(new CarbonPeriod('2021-08-01', '2021-08-31'))->countWeeks(); // 6
(new CarbonPeriod('2021-09-01', '2021-09-30'))->countWeeks(); // 5
(new CarbonPeriod('2021-12-31', '2022-01-01'))->countWeeks(); // 1
(new CarbonPeriod('2021-12-31', '2022-01-03'))->countWeeks(); // 2