A Laravel library for attaching files to Eloquent models.
The Laravel Attachment Library can be installed using Composer by running the following command:
$ composer require van-ons/laravel-attachment-library
After downloading the dependency, run the following command to install all the migrations and assets:
$ php artisan attachment-library:install
To enable file attachments in your Eloquent models, add the HasAttachments
trait to your model class:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments;
class ModelName extends Model
{
use HasAttachments;
// ...
}
After that you should be able to link attachments to your model as follows:
// Retrieve attachment.
$attachment = \VanOns\LaravelAttachmentLibrary\Models\Attachment::find($attachmentId);
// Retrieve your model.
$myModel = ModelName::find($modelId);
// Link attachment to your model.
$myModel->attachments()->attach($attachment);
Please see the documentation for detailed information about installation and usage.
Please see contributing for more information about how you can contribute.
Please see changelog for more information about what has changed recently.
Please see upgrading for more information about how to upgrade.
Please see security for more information about how we deal with security.
We would like to thank the following contributors for their contributions to this project:
The scripts and documentation in this project are released under the MIT License.