Download the PHP package codewiser/simple-files without Composer
On this page you can find all versions of the php package codewiser/simple-files. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codewiser/simple-files
More information about codewiser/simple-files
Files in codewiser/simple-files
Package simple-files
Short Description Light-weight file manager for Laravel
License MIT
Informations about the package simple-files
Simple lightweight storage
No database, only local filesystem.
Every model keeps its files isolated from each over. Path to files formed from model's morph name and its primary key.
Do not forget to
enforceMorphMap
inAppServiceProvider
.
Define storage
Implement Attachmentable
contract on Model
.
In the example below the model will keep files on default disk at post/{id}
path.
Uploading files
You may add files from UploadedFile
, from local path or remote url.
You may upload multiple files at once.
Removing files
File path
attribute is a relative path to a disk, e.g. post/1/test.png
.
Use path
attribute to delete file. You may delete multiple files at once.
To remove all files call flush
method on Storage
:
List files
To get collection with all files call files
method on Storage
:
Storage
object is Arrayable
too. It returns the same:
File object
File object has the same methods as Laravel Storage Facade: exists
, size
,
lastModified
, delete
, checksum
, url
etc.
Every stored file represented with such array:
File
object implements Responsable
and Attachable
, so you may use it as
Response
and in Notification
or Mailable
.
Singular Storage
Sometimes we need the model to have only one file. We may create such a storage:
When you upload next file to a storage, all previous files will be removed.
Singular storage has only one file, so files
collection will contain only one
element maximum. You may use file
method instead.
Storage Pool
The model may have few storages at the same time. Storages must have unique names (aka buckets).
Then we may get the exact bucket:
Default storage
It is allowed to have one default storage in a pool:
Call storage
without bucket name to get the default one.
Pool response
You may add a method to a model, that will return Pool
object with all
buckets defined:
Then you may use this method in api resource:
Pool toArray
method will return an array with every bucket and its file(s).
Singular storage provides file
attribute, that may be null
if no file were uploaded. Base storage provides files
array, that may be
empty.
Downloading files
The file is directly accessible only then published in public local filesystem. In other cases — private or cloud filesystem — application needs a controller to make files accessible to the users.
Let's say we have such private disk in config/filesystems.php
:
If so, file url would be about private/post/1/test.png
(for default bucket)
or private/post/1/bucket/test.png
(for named bucket).
We suggest to use a controller \Codewiser\Storage\StorageController
, that
is looks so:
All you need is to declare a route: