PHP code example of kesoji / laravel-removable-global-scopes

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

    

kesoji / laravel-removable-global-scopes example snippets


use Illuminate\Database\Eloquent\Model;
use Kesoji\RemovableGlobalScopes\RemovableGlobalScopes;

class User extends Model
{
    use RemovableGlobalScopes;
    
    // Your model code...
}

// Remove by name
User::removeGlobalScope('active');

// Remove by class
User::removeGlobalScope(ActiveScope::class);

// Remove by instance
User::removeGlobalScope(new ActiveScope);

User::removeGlobalScopes(['active', 'verified', TenantScope::class]);

// Temporary removal for a single query
User::withoutGlobalScope('active')->get();

// Temporary removal of multiple scopes
User::withoutGlobalScopes(['active', 'verified'])->get();

// Remove and store original scopes
$originalScopes = User::removeGlobalScope('active');

// Do something without the scope...

// Restore if needed
if (isset($originalScopes[User::class]['active'])) {
    User::addGlobalScope('active', $originalScopes[User::class]['active']);
}