Package Data | |
---|---|
Maintainer Username: | proshore |
Maintainer Contact: | babish@proshore.eu (Proshore Nepal) |
Package Create Date: | 2016-09-06 |
Package Last Update: | 2016-09-07 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:25:52 |
Package Statistics | |
---|---|
Total Downloads: | 815 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 3 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Basic image upload and thumbnail management package for laravel5.
First, pull in the package through Composer.
"require": {
"proshore/laravel-image-upload": "dev-master"
}
And then, if using Laravel 5, include the service provider within config/app.php
.
'providers' => [
LaravelImage\ImageUploadServiceProvider::class,
];
And, for convenience, add a facade alias to this same file at the bottom:
'aliases' => [
'ImageHelper' => LaravelImage\Image::class,
];
Finally publish the configuration
php artisan vendor:publish --provider="LaravelImage\ImageUploadServiceProvider"
You can add default thumbnail configuration to config/laravelimage.php
.
Within your controllers, get access to image upload service via dependency injection
class ContentsController extends Controller
{
...
protected $file;
/**
* @param ImageUploadService $file
*/
public function __construct(ImageUploadService $file)
{
...
//set properties for file upload
$this->file = $file;
$this->file->setUploadField('image'); //default is image
$this->file->setUploadFolder('contents'); //default is public/uploads/contents
}
...
And then, in your store or update method you can perform image upload
/**
* Store method
*/
public function store(ContentRequest $request)
{
$input = $request->all();
if (Input::hasFile('image') && $this->file->upload()) {
//file is uploaded, get uploaded file info
$uploadedFileInfo = $this->file->getUploadedFileInfo();
...
//do whatever you like with the information
$input = array_merge($input, $uploadedFileInfo);
}
...
}
/**
* Update method
*/
public function update(Request $request, $id)
{
...
if (Input::hasFile('image') && $this->file->upload()) {
...
//remove old files
if ( ! empty($model->file_path)) {
$this->file->clean(public_path($model->file_path), true);
}
}
...
}
Display from already registered thumbnails. It will try to generate new thumb if registered thumbnail doesn't exist.
{!!
\LaravelImage\LaravelImage::image($model->file_path, $model->image, [
'alt' => $model->original_file_name,
'size' => 'thumb'
])
!!}
Or, create image of custom size at runtime
{!!
\LaravelImage\LaravelImage::image($model->file_path, $model->image, [
'alt' => $model->original_file_name,
'size' => [
'custom' => ['w' => 300, 'h' => 200, 'crop' => true]
]
])
!!}