PHP code example of maxkhim / laravel-storage-dedupler
1. Go to this page and download the library: Download maxkhim/laravel-storage-dedupler 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/ */
maxkhim / laravel-storage-dedupler example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Maxkhim\Dedupler\Traits\Deduplable;
class Post extends Model
{
use Deduplable;
}
$post = new Post([...]);
// First upload - file is stored
$file1 = $post->storeUploadedFile($sameFile);
OR
$file1 = Dedupler::storeFromUploadedFile($sameFile);
// Second upload - returns existing UniqueFile, no duplicate created
$file2 = $post->storeUploadedFile($sameFile);
OR
$file2 = Dedupler::storeFromUploadedFile($sameFile);
$file1->id === $file2->id; // true - same database record and same file in storage
// Using the trait on your model
$post->attachUniqueFile($sha1_hash);
// Or via the Facade
Dedupler::attach(string $fileHash, Model $model, array $pivotAttributes = []);
// Using the trait
$post->detachUniqueFile($sha1_hash);
// Or via the Facade
Dedupler::detach(string $fileHash, Model $model);