novius/laravel-easy-upload

This packages makes it way easier to deal with file uploads and src

Installs: 3 155

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Language:HTML

1.2.0 2018-11-06 13:41 UTC

This package is auto-updated.

Last update: 2024-04-26 10:24:14 UTC


README

Travis Packagist Release Licence

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/*',
]) }}