diff --git a/examples/laravel-image-optimization/.editorconfig b/examples/laravel-image-optimization/.editorconfig new file mode 100644 index 00000000..6537ca46 --- /dev/null +++ b/examples/laravel-image-optimization/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/examples/laravel-image-optimization/.env.example b/examples/laravel-image-optimization/.env.example new file mode 100644 index 00000000..892bd968 --- /dev/null +++ b/examples/laravel-image-optimization/.env.example @@ -0,0 +1,48 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +CLOUDINARY_URL= + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=root +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/examples/laravel-image-optimization/.gitattributes b/examples/laravel-image-optimization/.gitattributes new file mode 100644 index 00000000..967315dd --- /dev/null +++ b/examples/laravel-image-optimization/.gitattributes @@ -0,0 +1,5 @@ +* text=auto +*.css linguist-vendored +*.scss linguist-vendored +*.js linguist-vendored +CHANGELOG.md export-ignore diff --git a/examples/laravel-image-optimization/.gitignore b/examples/laravel-image-optimization/.gitignore new file mode 100644 index 00000000..0f7df0fb --- /dev/null +++ b/examples/laravel-image-optimization/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/public/hot +/public/storage +/storage/*.key +/vendor +.env +.env.backup +.phpunit.result.cache +Homestead.json +Homestead.yaml +npm-debug.log +yarn-error.log diff --git a/examples/laravel-image-optimization/.styleci.yml b/examples/laravel-image-optimization/.styleci.yml new file mode 100644 index 00000000..1db61d96 --- /dev/null +++ b/examples/laravel-image-optimization/.styleci.yml @@ -0,0 +1,13 @@ +php: + preset: laravel + disabled: + - unused_use + finder: + not-name: + - index.php + - server.php +js: + finder: + not-name: + - webpack.mix.js +css: true diff --git a/examples/laravel-image-optimization/.vscode/settings.json b/examples/laravel-image-optimization/.vscode/settings.json new file mode 100644 index 00000000..0c11f650 --- /dev/null +++ b/examples/laravel-image-optimization/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "i18n-ally.localesPaths": [ + "resources/lang" + ] +} diff --git a/examples/laravel-image-optimization/README.md b/examples/laravel-image-optimization/README.md new file mode 100644 index 00000000..818438db --- /dev/null +++ b/examples/laravel-image-optimization/README.md @@ -0,0 +1,116 @@ +## Laravel Cloudinary Image Upload App + +## Getting started + +- Please ensure you have php <= 7.2 and composer installed on your machine +- Clone this repo +- Run `composer install` +- Set your environment variable in your `.env` file: `CLOUDINARY_URL=xxxxxxxxxxxx` +- Run `php artisan serve` +- Access the `/upload` route to test uploads +- Access the `/` route to test the image and video component + +## Laravel Controller in Use + +- app/Http/Controllers/FileUploadController.php + +## Blade Component in use for video and image tag + +- resources/views/welcome.blade.php + +## View for upload + +- resources/views/upload.blade.php + +```php + +// Upload an Image File to Cloudinary with One line of Code +$uploadedFileUrl = Cloudinary::upload($request->file('file')->getRealPath())->getSecurePath(); + +// Upload an Video File to Cloudinary with One line of Code +$uploadedFileUrl = Cloudinary::uploadVideo($request->file('file')->getRealPath())->getSecurePath(); + +// Upload any File to Cloudinary with One line of Code +$uploadedFileUrl = Cloudinary::uploadFile($request->file('file')->getRealPath())->getSecurePath(); + +// Upload an Image File to Cloudinary with One line of Code +$uploadedFileUrl = cloudinary()->upload($request->file('file')->getRealPath())->getSecurePath(); + +// Upload an Video File to Cloudinary with One line of Code +$uploadedFileUrl = cloudinary()->uploadVideo($request->file('file')->getRealPath())->getSecurePath(); + +// Upload any File to Cloudinary with One line of Code +$uploadedFileUrl = cloudinary()->uploadFile($request->file('file')->getRealPath())->getSecurePath(); + +// Store the uploaded file in the "anaconda" directory on Cloudinary +$result = $request->file('file')->store('anaconda', 'cloudinary'); + +// Store the uploaded file on Cloudinary +$result = $request->file('file')->storeOnCloudinary(); + +// Store the uploaded file on Cloudinary +$result = $request->file->storeOnCloudinary(); + +// Store the uploaded file in the "lambogini" directory on Cloudinary +$result = $request->file->storeOnCloudinary('lambogini'); + +// Store the uploaded file in the "lambogini" directory on Cloudinary with the filename "prosper" +$result = $request->file->storeOnCloudinaryAs('lambogini', 'prosper'); + + +$result->getPath(); // Get the url of the uploaded file; http +$result->getSecurePath(); // Get the url of the uploaded file; https +$result->getSize(); // Get the size of the uploaded file in bytes +$result->getReadableSize(); // Get the size of the uploaded file in bytes, megabytes, gigabytes or terabytes. E.g 1.8 MB +$result->getFileType(); // Get the type of the uploaded file +$result->getFileName(); // Get the file name of the uploaded file +$result->getOriginalFileName(); // Get the file name of the file before it was uploaded to Cloudinary +$result->getPublicId(); // Get the public_id of the uploaded file +$result->getExtension(); // Get the extension of the uploaded file +$result->getWidth(); // Get the width of the uploaded file +$result->getHeight(); // Get the height of the uploaded file +$result->getTimeUploaded(); // Get the time the file was uploaded +``` + +**Attach Files** to Laravel **Eloquent Models**: + +```php +$page = Page::create($this->request->input()); +$page->attachMedia($file); // Example of $file is $request->file('file'); + +$page = Page::find(2); +$page->attachMedia($file); // Example of $file is $request->file('file'); + +$filesBelongingToSecondPage = Page::find(2)->fetchAllMedia(); + +$fileBelongingToSecondPage = Page::find(2)->fetchFirstMedia(); + +$fileBelongingToSecondPage = Page::find(2)->fetchLastMedia(); + +$page = Page::find(2); +$page->updateMedia($file); // Example of $file is $request->file('file'); + +$page = Page::find(2); +$page->detachMedia($file) // Example of $file is $request->file('file'); +``` + +**Upload Files Via An Upload Widget**: + +Use the `x-cld-upload-button` Blade component that ships with this Package like so: + +``` + + +
+ ... + @cloudinaryJS + + +