#Laravel Ajax File Upload
Begin by installing this package through Composer:
composer require ehel/laravelfileupload
Next, add FileUploadServiceProvider to the providers array of config/app.php:
'providers' => [
//...
Ehel\FileUpload\FileUploadServiceProvider::class,
//...
];
Next, add class alias to the aliases array of config/app.php:
'aliases' => [
// ...
'FileUpload' => Ehel\FileUpload\FileUploadFacade::class
// ...
],
Finnaly, run :
php artisan vendor:publish
###Step 1: Generate Buttons
{!!FileUpload::buttons($uploadDirectory, $className) !!}
###Step 2: Generate Script
{!!FileUpload::script($uploadSuccess, $uploadFail, $deleteSuccess, $deleteFail, $ajaxUploadFail) !!}
##Attention Jquery and Bootstrap are required.
##Save file path to database Package generate a hidden input with file path, so you can save file path to database.
<input type="hidden" name="file_path" value="your_file_path">
##Example
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link href="bootstrap.min.css" rel="stylesheet"">
</head>
<body>
<div class="container">
{!!FileUpload::buttons('photos','uploadButtons') !!}
</div>
</body>
<script src="jquery-2.2.1.js"></script>
<script>
{!!FileUpload::script('console.log("Success");','console.log("Error");', 'console.log("Deleted");', 'console.log("Can\'t delete");', 'console.log("Here is an ajax error on upload");') !!}
</script>
</html>