PHP code example of syntech / globalscopes

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

    

syntech / globalscopes example snippets


return [

    /*
    |--------------------------------------------------------------------------
    | Global Query Methods
    |--------------------------------------------------------------------------
    |
    | Define global query methods for all Eloquent models.
    |
    */

    'methods' => [
        'approved' => function ($query) {
            return $query->where('status', 1)->where('approved', 1);
        },
    ],

    /*
    |--------------------------------------------------------------------------
    | Global Attributes
    |--------------------------------------------------------------------------
    |
    | Define global attributes for all Eloquent models.
    |
    */

    'attributes' => [
        'image' => function ($value) {
            return $value ? $value : asset('images/default.png');
        },
    ],

    /*
    |--------------------------------------------------------------------------
    | Global Scopes
    |--------------------------------------------------------------------------
    |
    | Define global scopes to be applied to all Eloquent models.
    |
    */

    'scopes' => [
        'approved' => 'status = 1 AND approved = 1',
    ],
];
bash
php artisan vendor:publish --provider="Syntech\GlobalScopes\GlobalScopesServiceProvider"