PHP code example of sofa / laravel-scopes

1. Go to this page and download the library: Download sofa/laravel-scopes 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/ */

    

sofa / laravel-scopes example snippets


        'providers' => [
            // ...
            Sofa\LaravelScopes\ServiceProvider::class,
            // ...
        ],
    

// Given it's September 11th, 2015

// Query\Builder: count users created in August
DB::table('users')->lastMonth()->count();

// Eloquent\Buidler: get users created on September 10th
User::yesterday()->get();

// count users who logged-in in 2014 & 2015
User::periods('year', 1, 'last_login', true)->count();

// count users created in 2014 & 2015
User::periods('year', -1, null, true)->count();
// or
User::periods('year', -1, true)->count();

// Get subscriptions expiring in October
User::where(...)->nextMonth()->get();

// Get subscriptions expired in past 7 days
User::has(...)->periods('day', -7)->get();

// Get subscriptions expiring in next 30 days
User::periods('day', 30)->get();