Download the PHP package givanov95/laravel-attachments without Composer

On this page you can find all versions of the php package givanov95/laravel-attachments. 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 laravel-attachments

givanov95/laravel-attachments

Polymorphic file & image attachments for Laravel.

What's included

Install

Configuration

Defaults in config/attachments.php (publishable):

Override middleware to add 'verified', role guards, custom guards, etc. The image/file routes are registered under this middleware stack. abilities maps the two policy abilities the routes check (see Stored file names first.

Usage

On a model

In a controller

Reading attachments

URL access

Frontend never constructs paths — the model exposes url:

Routes

Auto-registered (id-based, behind ['web', 'auth'] by default):

Method Path Name
DELETE /images/{image} images.destroy
PUT /images/order images.order
DELETE /files/{file} files.destroy
PUT /files/order files.order
GET /files/{file}/download files.download

The order endpoints accept { orderArray: [id, id, ...] } and rewrite the order column to the array's position (1-indexed).

Authorization

auth only proves the visitor is logged in — it says nothing about whose attachment they are touching. Since v1.3.0 every route authorizes the attachment against the model it hangs off (fileable / imageable) through Laravel's Gate:

Route Ability checked on the parent model
files.download view
images.destroy, files.destroy update
images.order, files.order update (for every parent referenced in orderArray; one foreign id rejects the whole request)

So each model that uses HasImages / HasFiles needs a policy with these abilities:

The check fails closed: a parent model without a policy, or an attachment whose parent no longer exists, gets a 403. If your policies use other ability names, remap them in config/attachments.php under abilities.

Upgrading from < 1.3.0: add the policies above before updating, otherwise the routes will answer 403 for every user. Versions up to 1.2.0 let any authenticated user delete, reorder or download other users' attachments (GHSA-6vf2-w3m8-6jqm) — update as soon as the policies are in place.

Stored file names

UploadHelper stores uploads as <sanitized-stem>_<time>_<uniqid>.<ext>. The extension is derived from the detected content type (never from the client-supplied name). It is kept only if it is on the safe default list; anything else is stored as .bin:

Kind Extensions
Images jpg jpeg png gif webp avif heic heif bmp tif tiff
Documents pdf txt csv rtf doc docx xls xlsx ppt pptx odt ods odp
Archives zip 7z rar gz tar
Audio / video mp3 m4a wav ogg mp4 mov webm

Content a browser renders on your domain (html, xhtml, svg, xml, …) and anything a server may execute (php, phtml, cgi, sh, …) therefore ends up as .bin, and is served as a download rather than a page. The client's original name is kept in original_name and used for downloads. You should still validate uploads in your own requests.

Allowing more extensions (dangerous)

To keep an extension that is not on the list, add it explicitly in config/attachments.php:

Warning: files are served straight from the storage disk. On a public disk an uploaded html, htm, xhtml, svg, xml or js file runs scripts on your app's domain: this is stored XSS, and it can steal sessions or perform actions as the logged-in user. php, phtml, cgi and similar may even be executed by the web server. Only add such extensions when every uploader is trusted, or when the disk is not publicly served or the web server sends these files as downloads (Content-Disposition: attachment).

Entries are case-insensitive, a leading dot is ignored ('.SVG' works), and invalid values are skipped.

Development

Pre-commit hook

composer install / composer update installs a pre-commit hook into .git/hooks/ via the givanov95/laravel-git-hooks plugin (the hook itself lives in vendor/). Before each commit it runs php-cs-fixer on staged files (when configured), blocks leftover dd( / dump( calls and runs the test suite.

It is a fast-feedback gate only. Skip it for one commit with SKIP_HOOK=1 git commit ... (or git commit --no-verify).

CI

GitHub Actions (.github/workflows/ci.yml) runs the tests and PHPStan on PHP 8.3 and 8.4 for every pull request and push to main. Dependabot keeps dependencies and the workflow up to date.

License

MIT


All versions of laravel-attachments with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/filesystem Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.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 givanov95/laravel-attachments contains the following files

Loading the files please wait ...