Looking to hire Laravel developers? Try LaraJobs

laravel-attachments maintained by sehrgut

Description
Traits which make attaching files to your Eloquent models super easy!
Author
Last update
2018/06/14 17:06 (dev-master)
License
Links
Downloads
2 704

Comments
comments powered by Disqus

Laravel Attachments

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());