PHP code example of jangaraev / eloquent-model-advisory-lock

1. Go to this page and download the library: Download jangaraev/eloquent-model-advisory-lock 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/ */

    

jangaraev / eloquent-model-advisory-lock example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Jangaraev\EloquentModelAdvisoryLock\AppliesAdvisoryLock;

class Foo extends Model
{
    use AppliesAdvisoryLock;
    
    // ...
}

// wrap you DB-intensive operations as a callable to the advisoryLock call
static::advisoryLock(fn () => $this->coolRelationship()->firstOrCreate());