Download the PHP package djurovicigoor/lara-files without Composer

On this page you can find all versions of the php package djurovicigoor/lara-files. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lara-files

LaraFiles

Packagist Downloads Packagist Version License: MIT Run tests Fix Code Style

📦 Lara Files

Lara Files is a lightweight and flexible Laravel package for handling file uploads for Eloquent models.

It provides a fully-featured LaraFile model, a powerful upload service, and clean integration via traits—allowing you to easily attach files (images, documents, etc.) to any model in your application.

Built for Laravel 10, 11, and 12 support in mind, and it's ideal for modern Laravel projects that need organized file management.

lara-files preview

Versions

Lara files Laravel
v2.x 10.x - 12.x
v1.x 5.5 - 9.x

Installation

Lara files can be installed via Composer:

The service provider will automatically get registered if not you can manually add it in your bootstrap/providers.php file:

Now you can publish a service provider:

Config file

This is the default content of the config file:

Preparing the database

You need to run migrations to create lara_files table

LaraFile model

The LaraFile model provides one MorphToMany relation by default. If you want to use more than default laraFile() relation, you should modify types array in config/lara-files.php

Every type you add in this array, represents the new relation with LaraFile model but filtered with certain type. For avatar example you have all those methods available:

All of those methods and properties are applicable for any type in this types array.

Multiple disks support

By default, the library will store its files on disk from the config/env file. If you want a dedicated disk you should add a disk to config/filesystems.php. Library support Laravel's default disk system and all disk with s3 driver. If you want to use disk with s3 driver you have to install league/flysystem-aws-s3-v3

Preparing your model

To associate files with a model, the model must implement the following trait:

Associating HTTP file/files

You can associate a file with a model like this:

These two parameters are required and file will be directly uploaded to disk you set in config/lara-files.php. This method will return LaraFile model. If you want to customize the upload process, you can use addHttpFile() method instead. This method will be return service object which you can use to customize the upload process.

You can chain multiple methods on $fileUploadObject object:

Custom disk

You can set custom disk but disk must be presented in config/filesystems.php disks array.

Custom visibility

You can set visibility of uploaded file, visibility must be one of ['public', 'private']

Custom name

Set custom name for file without extension

Custom properties

Custom properties are expected as array and will be stored as json string in database.

At the end, to finish upload process you have to call upload() method without any parameters.

If you need to upload multiple files with same parameters, you can use uploadHttpFiles() method instead.

Associating base64 representation of file/files

You can associate a base64 representation of file with a model like this:

These two parameters are required and file will be directly uploaded to disk you set in config/lara-files.php. This method will return LaraFile model. If you want to customize the upload process, you can use addBase64File() method instead. This method will be return service object which you can use to customize the upload process.

You can chain multiple methods on $fileUploadObject object:

Custom disk

You can set custom disk but disk must be presented in config/filesystems.php disks array.

Custom visibility

You can set visibility of uploaded file, visibility must be one of ['public', 'private']

Custom name

Set custom name for file without extension

Custom properties

Custom properties are expected as array and will be stored as json string in database.

At the end, to finish upload process you have to call upload() method without any parameters.

If you need to upload multiple files with same parameters, you can use uploadBase64Files() method instead.

This method will return Collection of LaraFile models.

Upload file without model (temp file)

If you need to upload and store file without certain model you need to call the static method of the LaraFileUploader class:

Ordering files

This package has a built-in feature to help you order the files in your project. By default, all inserted files are arranged in order by their time of creation (from the oldest to the newest) using the order column of the lara-files table.

You can easily reorder a list of media by calling LaraFile::setNewOrder. This function reorders the records so that the record with the first ID in the array receives the starting order (default is 1), the second ID gets starting order + 1, and so on. An optional starting order value can be provided as second parameters.

Of course, you can also manually change the value of the order.

Using custom properties

When adding a file to the model you can pass an array with custom properties:

There are some methods to work with custom properties:

If you are setting or removing custom properties outside the process of adding media then you will need to persist/save these changes:

You can also specify a default value when retrieving a custom property.

If you're dealing with nested custom properties, you can use dot notation.

LaraFile model methods

When you get LaraFile model instance, you have access to certain attributes and methods for current file:

You have full url accessible trough browser for all disk except if file is stored using local disk.

You can get full path.

You can get size of the file in bytes.

You can get mime type of the file.

You can get last modified at time of the file.

Calling getContents method you can get contents for the file.

Calling download method you can directly download the file.

If you want to move file to another disk you need to call changeDisk method.

If you need to change visibility of the file you have to call changeVisibility method.

Using the getTemporaryUrl method, you may create temporary URLs to files stored using the local and s3 drivers. This method accepts DateTime instance specifying when the URL should expire and additional S3 request parameters, you may pass the array of request parameters as the second argument to the getTemporaryUrl method:

Change log

Please see the changelog.md for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Donate

If you found this project helpful or you learned something from the source code and want to appreciate

Credits

Contributors

Name Changes Date
@niladam Refactor to PSR2 and simplify accessor pull request #2 2019-05-18
@chefe Fix typo in exception message pull request #5 2019-05-23
@omly97 Laravel 10 - Fix - Error Call to undefined function str_plural pull request #6 2023-08-17

License

MIT. Please see the license file for more information.


All versions of lara-files with dependencies

PHP Build Version
Package Version
Requires doctrine/dbal Version ^3.9
php Version ^8.2 || ^8.3 || ^8.4
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0
illuminate/support Version ^10.2|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package djurovicigoor/lara-files contains the following files

Loading the files please wait ....