codekj / laravel-date-scopes
Provides date scopes for Laravel Eloquent models
Installs: 1 444
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- nesbot/carbon: ^2.0
This package is auto-updated.
Last update: 2024-09-07 06:48:49 UTC
README
Provides date scopes for Laravel Eloquent models
Requirements
- Composer
- Laravel or Lumen
- PHP >= 7.1
Installation
Install composer package
composer require codekj/laravel-date-scopes
Usage
Use DateScopes
trait in model
<?php
namespace App;
use CodeKJ\Laravel\Traits\DateScopes\DateScopes;
class User extends Model
{
use DateScopes;
/* ... */
}
Methods
Default date field:
created_at
. All methods can have custom date field parameter, exampletoday('updated_at')
Examples
// Get records only from today
$todayUsers = User::today()->get();
// Get records from last minute (previous minute)
// Example: if time is 10:30, you will get records ONLY from 10:29
$lastMinuteUsers = User::lastMinute()->get();
// Get records from an hour ago until this moment
// Example: if time is 10:30, you will get records from 09:30 until 10:30
$hourAgoUsers = User::hourAgo()->get();
// Get records from 2 weeks ago until this moment
// Example: if date is 2020-08-30 10:30:00, you will get records from 2020-08-16 10:30:00 until 2020-08-30 10:30:00
$weeksAgoUsers = User::weeksAgo(2)->get();
License
The MIT License (MIT)