Download the PHP package teamteatime/laravel-filer without Composer
On this page you can find all versions of the php package teamteatime/laravel-filer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teamteatime/laravel-filer
More information about teamteatime/laravel-filer
Files in teamteatime/laravel-filer
Package laravel-filer
Short Description A simple Laravel ORM file attachment solution supporting multiple relationship types
License MIT
Informations about the package laravel-filer
Please be aware that this package is not designed to handle uploading or image manipulation. It's simply designed to compliment other packages and tools that already exist in Laravel. If you're looking for a more feature-complete attachments solution, take a look at CodeSleeve/stapler.
Installation
Step 1: Install the package
Install the package via Composer:
Add the service provider to your config/app.php
:
If your app defines a catch-all route, make sure you load this service provider before your app service providers.
Step 2: Publish the package files
Run the vendor:publish command to publish Filer's migrations:
php artisan vendor:publish
Step 3: Update your database
Run your migrations:
php artisan migrate
Step 4: Update your models
Add attachment support to your models by using the HasAttachments trait:
Configuration
Filer requires no configuration out of the box in most cases, but the following options are available to you in config/filer.php
:
Option | Type | Description | Default |
---|---|---|---|
routes | Boolean | Determines whether or not to automatically define filer's routes. If you set this to false , you can optionally use \TeamTeaTime\Filer\Filer::routes($router, $namespace) in your routes.php. |
true |
route_prefix | string | If routes are enabled, this is used for all route prefixes. | files |
hash_routes | Boolean | Enables unique hashes for local files to obfuscate their IDs in routes. | false |
hash_length | string | The length to use when generating hashes for local files. | 40 |
path | Array | Contains the relative and absolute paths to the directory where your attachment files are stored. | storage_path('uploads') |
append_querystring | Boolean | If enabled, attachment URLs include a querystring containing the attachment's updated_at timestamp. This prevents out of date attachments from being loaded by the browser. | true |
cleanup_on_delete | Boolean | If enabled, Filer will attempt to delete local files referenced by deleted attachments. | true |
Usage
To attach a file or URL, use the attach()
method on your model. This method will accept any of the following:
...a local file path
...an instance of SplFileInfo
Symfony\Component\HttpFoundation\File\File
,Symfony\Component\HttpFoundation\File\UploadedFile
andIlluminate\Http\UploadedFile
are extensions ofSplFileInfo
and Laravel Requests contain the latter by default.
...or a URL
You can also specify a key (which uniquely identifies the attachment), a title, and/or a description using the options array:
By default, attachments are associated with user IDs using Auth::id()
. You can override this at call time:
Depending on what you pass to this method, the item will be stored as either a TeamTeaTime\Filer\LocalFile
or a TeamTeaTime\Filer\Url
. You can later call on attachments via the attachments
relationship. Examples are provided below.
Displaying a list of attachments in a view
Retrieving an attachment by ID or key
Accessing an attachment's properties and type-specific properties
Generating URLs
The getUrl()
and getDownloadUrl()
methods above will return different values based on the attachment type; if it's a local file, they will return the 'view' and 'download' routes respectively, otherwise they'll return the URL that was attached.
For local files, the provided routes can be generated with a file ID or hash:
Note that depending on the file's MIME type, the browser may begin a download with both of these routes.