novius / laravel-easy-upload
This packages makes it way easier to deal with file uploads and src
Installs: 3 173
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: >=7.1
README
Treat file uploading as if it was just a text input
Installation
composer require novius/laravel-easy-upload
Then add this to config/app.php
:
// in 'providers' => [ ... ] Novius\EasyUpload\EasyUploadServiceProvider::class, // in 'aliases' => [ ... ] 'Upload' => Novius\EasyUpload\Support\Renderer::class,
Use
In a view:
<form action="…"> <input name="title"> <textarea name="description"> {{ Upload::input(['name' => 'avatar_src']) }} </form>
This will provide a <input type="hidden">
tag and a <input type="file">
tag. As soon as the user specify a file, it will be uploaded through ajax, and the resulting file src will be stored in the hidden inout value attribute.
Possible options are:
{{ Upload::input([ 'name' => 'avatar_src', // default: file_src 'attribute' => 'data-name', // default: name 'value' => 'upload/my-image-1234.jpg', 'class' => 'any-class-you-want or-several-at-the-same-time' ]) }} {{ Upload::link([ // show the uploaded file link 'link_attributes' => 'class="my-link"', 'accept' => '.pdf,.zip', ]) }} {{ Upload::image([ // preview the uploaded picture 'accept' => 'image/*', ]) }}