novius/laravel-easy-upload

此包让处理文件上传和源变得更加简单

1.2.0 2018-11-06 13:41 UTC

This package is auto-updated.

Last update: 2024-09-26 11:08:12 UTC


README

Travis Packagist Release Licence

将文件上传视为普通的文本输入

安装

composer require novius/laravel-easy-upload

然后在 config/app.php 中添加以下内容

// in 'providers' => [ ... ]
Novius\EasyUpload\EasyUploadServiceProvider::class,

// in 'aliases' => [ ... ]
'Upload' => Novius\EasyUpload\Support\Renderer::class,

使用

在视图中

<form action="">
    <input name="title">
    <textarea name="description">
    {{ Upload::input(['name' => 'avatar_src']) }}
</form>

这将提供一个 <input type="hidden"> 标签和一个 <input type="file"> 标签。当用户指定一个文件时,它将通过ajax上传,结果文件的源将被存储在隐藏输入的值属性中。

可能的选项包括

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