sehrgut / laravel-attachments
Traits which make attaching files to your Eloquent models super easy!
Installs: 2 704
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 2
Requires
- php: >=7.0.0
- intervention/image: ^2.4
This package is not auto-updated.
Last update: 2023-03-04 21:33:36 UTC
README
Create attachment database column
Create a database field (nullable string) for every attachment of a model, e.g.:
$table->string('profile_image')->nullable();
Define the attachments in your model like this:
protected $image_attachments = [ 'profile_image' => [ 'path' => 'uploads/user/avatar', 'defaults' => [ 'small' => '.jpg', 'medium' => '.jpg', 'large' => '.jpg', ], 'styles' => [ 'small' => '100', 'medium' => '500', 'large' => '1000' ] ], 'background_image' => [ 'path' => 'uploads/user/background', 'defaults' => [ 'small' => '.jpg', 'medium' => '.jpg', 'large' => '.jpg', ], 'styles' => [ 'small' => '100', 'medium' => '500', 'large' => '1000' ] ] ];
Using it
As simple as:
$me->updateImageAttachment('profile_image', $request->fileContent(), $request->fileType());