1. Go to this page and download the library: Download kevjo/laravel-collab 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/ */
kevjo / laravel-collab example snippets
use Kevjo\LaravelCollab\Traits\HasConcurrentEditing;
class Post extends Model
{
use HasConcurrentEditing;
}
// Acquire a lock
$result = $post->acquireLock(auth()->user());
if ($result->isFailed()) {
return back()->with('error',
"This post is being edited by {$result->getLockedBy()->name}"
);
}
// Release a lock
$post->releaseLock(auth()->user());
// Lock is also auto-released after model update (configurable)
$post->update($request->validated());
$post->isLocked(); // Is it locked by anyone?
$post->isLockedByUser(auth()->user()); // Is it locked by me?
$post->isLockedByAnother(auth()->user()); // Is it locked by someone else?
$post->lockOwner(); // Get the User who holds the lock
$post->lockExpiresAt(); // Carbon instance of expiration
$post->lockRemainingTime(); // Seconds until expiration
// Specify which route parameter to check
Route::put('/posts/{post}', [PostController::class, 'update'])
->middleware('collab.lock:post');
// Auto-detect all lockable models on the route
Route::put('/posts/{post}', [PostController::class, 'update'])
->middleware('collab.lock');