https://github.com/plusemon/laravel-file-uploader
Easy way to upload Laravel model related files from the request.
https://github.com/plusemon/laravel-file-uploader
eloquent laravel laravel-package php upload
Last synced: 3 months ago
JSON representation
Easy way to upload Laravel model related files from the request.
- Host: GitHub
- URL: https://github.com/plusemon/laravel-file-uploader
- Owner: plusemon
- License: mit
- Created: 2022-06-01T05:19:48.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-02T04:54:50.000Z (over 2 years ago)
- Last Synced: 2025-12-14T23:08:15.772Z (7 months ago)
- Topics: eloquent, laravel, laravel-package, php, upload
- Language: PHP
- Homepage: https://packagist.org/packages/plusemon/uploader
- Size: 42 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Laravel Model Easy File Uploader
Easy way to upload laravel model related file from the requset.
## Basic Examples
```php
$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
// %20??%20'no-image-available.png'%20)
## 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
```bash
composer require plusemon/uploader
```
use HasUploader trait on the dedicated model
```php