PHP code example of plusemon / uploader

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

    

plusemon / uploader example snippets



$product = Product::first();

// Store file
$product->uploadRequestFile('image'); // attach $request->image into $product->image
$product->uploadRequestFile('image', 'thumbnail'); // attach $request->image into $product->thumbnail
$product->uploadRequestFile('image')->saveInto('thumbnail'); // save into custom column

// Update file
$product->uploadRequestFile('image')->updateInto('thumbnail'); // will delete old file and update the new file

// Delete file
$product->deleteFile('image');
$product->deleteWithFile('image'); // delete the model with file
$product->deleteWith('image'); // deleteWithFile() shorter

// Upload multiple files
$product->uploadRequestFiles('images')->getUploadedFiles(); // return the uploaded files as array
$product->uploadRequestFiles('images')->saveInto('thumbnails', true); // save as array into $product->thumbnails
$product->uploadRequestFiles('images')->saveAsArrayInto('thumbnails'); 

# Note: all the files will be save into /public/uploads/products/images/products-1.jpg


// Get the attached file url 
$product->urlOf('image') // https://website.com/uploads/products/images/products-1.jpg

// Render the file
//  <img src="{{ $product->urlOf('image') ?? 'no-image-available.png' ">


## Advance

// Intervention Image support
$product->uploadRequestFile('image')->image()->resize()->crop()->save();  

// custom file upload helper
$product->upload($request->file('image'), $module_name = 'products', $file_type = 'images', $unique_id = 123);






namespace App\Models;
use Plusemon\Uploader\HasUploader;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasUploader;
}