Facade
Alicia facade helps to use this package easily and faster. this facade contains a bunch of methods that in the next, we will introduce them.
Available methods
batch
Uploads and stores files and links at once.
use Hans\Alicia\Facades\Alicia;
Alicia::batch( request()->input('files') )->getData();
files
input can contain files and links.
upload
Uploads a single file on the server.
use Hans\Alicia\Facades\Alicia;
Alicia::upload( request()->file('file') )->getData();
external
Stores an external link on the database.
use Hans\Alicia\Facades\Alicia;
Alicia::external( request()->input('link') )->getData();
export
Creates different versions of uploaded image.
use Hans\Alicia\Facades\Alicia;
Alicia::upload( request()->file('file') )->export()->getData();
delete
Delete a model instance and its related files.
use Hans\Alicia\Facades\Alicia;
$model = Alicia::upload( request()->file('file') )->getData();
Alicia::delete($model);
batchDelete
Delete several models and their related files at once.
use Hans\Alicia\Facades\Alicia;
$modelA = Alicia::upload( request()->file('file') )->getData();
$modelB = Alicia::upload( request()->file('file') )->getData();
Alicia::batchDelete( [$modelA,$modelB->id] );
makeExternal
Sometimes you need to move your file to another server and access it using a link.
use Hans\Alicia\Facades\Alicia;
$model = Alicia::upload( request()->file('file') )->getData();
// Upload given file on another server and get its link
$link = 'https://www.file-server.dev/files/file-name.extension';
Alicia::makeExternal( $model,$link );
This make it easy to move your files to another server without doing heavy updates or re-creating you resources.
fromFile
If you have your file on the server and want to store it on database, you can use fromFile
method.
use Hans\Alicia\Facades\Alicia;
$file = '/path/to/file.extension';
$model = Alicia::fromFile( $file )->getData();
hlsExport
HLS is disabled by default, but if you want to get a HLS export for your uploaded video file, you can use hlsExport
method.
use Hans\Alicia\Facades\Alicia;
Alicia::upload( request()->file('file') )->hlsExport()->getData();
This method dispatch a job in the background to get HLS export for your video file.
getData
After you create a resource, you can call getData
method to get your created resources. if your action created one
model instance, this method returns a single model instance. for instance, when we upload a single file.
use Hans\Alicia\Facades\Alicia;
Alicia::upload( request()->file('file') )->getData();
But, if we call export
method after uploading an image or using batch
method, the created models could be more than
one instance, so getData
method returns a collection of created models.
use Hans\Alicia\Facades\Alicia;
Alicia::upload( request()->file('file') )->export()->getData();