PHP code example of omar-elnaghy / laradate-filters

1. Go to this page and download the library: Download omar-elnaghy/laradate-filters 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/ */

    

omar-elnaghy / laradate-filters example snippets



use Illuminate\Database\Eloquent\Model;
use OmarElnaghy\LaraDateFilters\Traits\Builder\PackageBuilder;

class YourModel extends Model
{
    public function newEloquentBuilder($query)
    {
        return new PackageBuilder($query);
    }
}

$startDate = Carbon::parse('2023-9-03');
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$direction = 'after';                                                                                     
$results = Post::filterByDateRange(2,'day',$startDate, $direction, $range)->get();           
 

    $results = Post::filterByDateRange(2,'day',$startDate, $direction, $range)->get();      
    $results = Post::filterByDateRange(2,'week',$startDate, $direction, $range)->get();      
    $results = Post::filterByDateRange(2,'hour',$startDate, $direction, $range)->get();      

$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::EXCLUSIVE;


    $results = Post::filterByDateSecondsRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateMinutesRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateHoursRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateDaysRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateWeeksRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateMonthsRange(2,$startDate, $direction, $range)->get();


// [Duration] is a number refer to the number of [Date Unit] you want to search in          
return Post::filterByDate(Duration)(Date Unit)Range($startDate, $direction, $range)->get();

$startDate = Carbon::parse('2023-09-03');
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$direction = 'after';

return Post::filterByDate5DayRange($startDate, $direction, $range)->get();

return Post::filterByDate6WeekRange($startDate, $direction, $range)->get();

return Post::filterByDate7MonthRange($startDate, $direction, $range)->get();
bash
php artisan vendor:publish --provider="OmarElnaghy\LaraDateFilters\ServiceProvider"