plusemon / uploader
Laravel model file upload helper package.
1.1.0
2022-12-05 15:53 UTC
Requires
- intervention/image: ^2.7
README
Easy way to upload laravel model related file from the requset.
Basic Examples
$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);
Installation
composer require plusemon/uploader
use HasUploader trait on the dedicated model
<?php namespace App\Models; use Plusemon\Uploader\HasUploader; use Illuminate\Database\Eloquent\Model; class Product extends Model { use HasUploader; }
You are ready to go... :)
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.