PHP code example of vhar / laravel-files

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

    

vhar / laravel-files example snippets


return [

    /*
     * Default filesystem disk.
     */
    'disk' => env('FILES_DISK', 'public'),

    /*
     * Reuse existing file records when checksum matches.
     */
    'deduplicate' => true,

    /*
     * Automatically delete files that are no longer attached.
     */
    'delete_orphan_files' => true,

    /*
     * Hash algorithm with used for deduplicates
    */
    'hash_algo' => 'sha1',
];

use Vhar\LaravelFiles\Facades\LaravelFiles;

$file = LaravelFiles::upload($request->file('image'));

$file = LaravelFiles::upload(
    $request->file('image'),
    'quiz/images',
    'public'
);

use Vhar\LaravelFiles\Facades\LaravelFiles;

$file = LaravelFiles::replace(
    $file,
    $request->file('image')
);

LaravelFiles::attach($news, $file);

LaravelFiles::attach($news, $file, 'gallery');

LaravelFiles::detach($news, $file);

LaravelFiles::detach($news, $file, 'gallery');

LaravelFiles::forceDelete($file);

LaravelFiles::exists($file);

use Vhar\LaravelFiles\Traits\HasFiles;

class Quiz extends Model
{
    use HasFiles;
}

// Get the first file
$news->file();

// Get the first file from a specific collection
$news->file('gallery');

// Get all files
$news->files()->get();

// Get files from a specific collection
$news->files('gallery')->get();

$news->addFile($file, 'gallery');

$news->removeFile($file, 'gallery');

$file->url();

$file->humanSize();

$file->size;

$file->mime_type;

$file->original_name;
bash
php artisan vendor:publish --tag=laravel-files-migrations  
php artisan migrate
bash
php artisan vendor:publish --tag=laravel-files-config
bash
php artisan vendor:publish --tag=laravel-files-migrations