Download the PHP package mustafaomar/laravel-fileuploader without Composer
On this page you can find all versions of the php package mustafaomar/laravel-fileuploader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mustafaomar/laravel-fileuploader
More information about mustafaomar/laravel-fileuploader
Files in mustafaomar/laravel-fileuploader
Package laravel-fileuploader
Short Description A simple package for uploading media and storing media urls in database
License MIT
Informations about the package laravel-fileuploader
Installation
You can install it via composer
$ composer require mustafaomar/laravel-fileuploader
Publishing
Publishing config file fileuploader.php
If you intend to store urls in database via this package, you need to publish the migration and model
If you want publish all
Configuration
disk
: A filesystem's disk
model
: The model class
url_column
: The name of the column you want to store the image link
Usage
There are serveral ways to start using laravel-fileuploader
Uploadable trait
You can use Uploadable
in your controller and we're done, you now have access to the uploader
method, example.
TestController.php
Notice: This image will be saved to the storage, and to be more specific it depends on how you're configuring the disk option in the fileuploader.php
and the default disk is public
So, this file will be stored in: /laravel-app/storage/app/public/products/[hashname]
Getting the url
You may want to get the url to store it in the database, you can return the url as following.
Now you can use asset(URL)
method to show this image somewhere.
You can also quickly pass the image to the uploader
method as the first argument, and path as the second.
Using Facade
Using app and make method
Just wanted to mention that you can use make
method to resolve the fileuploader
from the container.
Saving many files at once
You can of course, pass an array of images to the uploader
method or using saveMany
method, let's give it a try.
Saving urls in database
You can save the files in disk and save the generated urls in the database with one line of code, just don't forget to publish the migrations
Notice: I assume you have a model for example Product
and each product has many images, and in order make this work
you have to add a relation within that Product
like so:
Now you have to pass the newly created Product
model to toDatabase
method, see this example
Notice If you want to add other columns to media table feel free to do that, then you will need to pass these additional columns to toDatabase
method as the second paramater
Sometimes you may want to get the urls and do whatever you want with them.