sehrgut/laravel-attachments

Traits which make attaching files to your Eloquent models super easy!

dev-master 2018-06-14 15:06 UTC

This package is not auto-updated.

Last update: 2022-05-14 17:08:11 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());