Uploadcare for Laravel
This is a simple Laravel service provider for Uploadcare's official PHP library., (*1)
Installation
First, add this to your composer.json
file, (*2)
"require": {
"illuminate/html": "5.*",
"altitude/laravel-uploadcare": "~2.0.0"
}
Then, create config/uploadcare.php
with the following, (*3)
<?php
return array(
'public_key' => 'YOUR_UPLOADCARE_PUBLIC_KEY_HERE',
'private_key' => 'YOUR_UPLOADCARE_PRIVATE_KEY_HERE',
);
Finally, add the service provider and alias in your config/app.php
, (*4)
'providers' => array(
...
Illuminate\Html\HtmlServiceProvider::class,
Altitude\LaravelUploadcare\LaravelUploadcareServiceProvider::class,
);
'aliases' => array(
...
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class,
'Uploadcare' => Altitude\LaravelUploadcare\Facades\Uploadcare::class,
);
And you should be good to go., (*5)
Example
This Service extends Uploadcare's API class so you can use any of its methods., (*6)
It also provides the form macro Form::uploadcare($field_name, $value = null, $options = array())
., (*7)
app/Http/routes.php, (*8)
Route::get('/demo', function(){
return View::make('demo/demo');
});
Route::post('/demo', function(){
echo Uploadcare::getFile(Input::get('image'))->getUrl();
});
resources/views/demo/demo.blade.php, (*9)
<html>
<head>
<title>Uploadcare Demo</title>
</head>
<body>
<form method="POST" action="/demo">
{!! Form::uploadcare('image', null, array('data-crop' => '3:4')) !!}
<input type="submit">
</form>
{!! Uploadcare::scriptTag() !!}
</body>
</html>
For more information, please check the offical documentation, (*10)
Laravel 4.x
This library is still available for Laravel 4.x. Please use the older 1.x releases and check their README.md for usage., (*11)
License
MIT license, (*12)