PHP code example of getsidekicker / laravel-optimistic-locking

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

    

getsidekicker / laravel-optimistic-locking example snippets




class BlogPost extends Model {
    use OptimisticLocking;
}



$schema->integer('lock_version')->unsigned()->nullable();


\Reshadman\OptimisticLocking\StaleModelLockingException::class;


$blogPost->disableLocking();
$blogPost->enableLocking();


class BlogPost extends \Illuminate\Database\Eloquent\Model 
{
    use \Reshadman\OptimisticLocking\OptimisticLocking;
    
    protected $lock = false;
}


class BlogPost extends \Illuminate\Database\Eloquent\Model
{
    use \Reshadman\OptimisticLocking\OptimisticLocking;
    
    /**
     * Name of the lock version column.
     *
     * @return string
     */
    protected static function lockVersionColumn()
    {
        return 'track_version';
    }
}


$query->where('id', $this->id)
    ->where('lock_version', $this->lock_version)
    ->update($changes);