This Laravel package provides an easy, zero-conf way to implement simple and chunked uploading from frontend libraries like DropzoneJS or ResumableJS and implement custom asynchronous post-processing through listeners thanks to its use of Laravel Events.
You can install the package via composer:
composer require cybex/laravel-lodorTo get started with a simple HTML file upload, the only thing you really have to do is to set the action of your file upload form to the Lodor upload route:
<form id="upload-form" enctype="multipart/form-data" method="post" action="{{ Lodor::getUploadRoute() }}"> <label for="file">Upload a file with Lodor:</label> <input type="file" name="file" id="file-input" multiple /> <input type="submit"> </form>By default, Lodor registers a POST route at /uploadmedia, and all simple uploads go straight to the lodor/uploads directory in the storage path of your Laravel application.
The HTML form above will upload the file to your storage directory and, by default, return a JSON with a success indicator and uuid like:
{"success":true,"uuid":"ffb3dfe7-9029-4b9a-abfe-5e7485592561"} This setup is useful for asynchronous uploads using Javascripts, particularly when using Javascript libraries like Dropzone.js or Resumable.js.
If you want to process the form yourself instead after the upload completed, you may define a named route by the name of lodor_uploaded like this:
Route::post('/uploaded')->uses('SomeController@uploaded')->name('lodor_uploaded'); If this named route exists, Lodor will automatically redirect the request to the specified controller action instead of returning a JSON response. The controller method should be declared as follows:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class SomeController extends Controller { function uploaded(Request $request, bool $success, string $uuid, array $metadata, string $errorMessage = null) { // Do something here and handle the request returning some response, view or redirect. } }$requestcontains all request data of the file upload form.$successistrueif the upload succeeded, andfalseif not.$uuidcontains the unique id of the upload.$metadatais an array containing detail info about the uploaded file.$errormessagecontains the error message if the upload failed or is null otherwise.
composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email info@lupinitylabs.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate (thanks, Marcel!).