ewvlnet/dropzone 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ewvlnet/dropzone

Composer 安装命令:

composer require ewvlnet/dropzone

包简介

This package allows you to manage files in resources such as pages and posts in an laravel application.

README 文档

README

Dropzone is a package that allows you to upload files associated with resources such as users, posts and whatever else you want.

🔧 Installing in a Laravel project

See instructions at: https://ewvl.net/posts/laravel-package-dropzone

composer require ewvlnet/dropzone

Add the FileTrait in the Models you want to work with dropzone, for example in a Model Post.

use Ewvlnet\Dropzone\Models\Traits\FileTrait;

class Post extends Model
{
    use HasFactory, FileTrait;

    /* ... Rest of the code... */

Create the migration file below in your project 2022_01_01_000008_create_files_table

This migration file must be run after migrations it references foreign, so in the example below where we use as foreign of 'post_id' and 'user_id', we must be sure that these migrations have already been executed before, otherwise we will get an error, when you run your migrations. Set the date in the filename so it always runs last.

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return  void
     */
    public function up()
    {
         Schema::create('files', function (Blueprint $table) {
             $table->id();

             $table->unsignedBigInteger('user_id')->nullable();
             $table->unsignedBigInteger('post_id')->nullable();

             $table->string('name')->nullable();
             $table->string('type')->nullable();
             $table->string('url')->nullable();

             $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
             $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');

             $table->timestamps();
         });
    }

    /**
     * Reverse the migrations.
     *
     * @return  void
     */
    public function down()
    {
         Schema::dropIfExists('files');
    }
}

Run the migration

php artisan migrate

In the dropzone-uploader.blade.php and dropzone-gallery.blade.php files, push('css') and push('js') are used, remember to include this in your master layout to load the necessary scripts.

@stack('css')
@stack('js')

Now, you can include the blade component below in an edit.blade.php file for example.

<x-drozone-uploader mtype="post" ftype="image" :model="$post"/>

If you haven't already done so, run the command to publish the "symbolic link", to be able to see the images of the storage folder.

php artisan storage:link

To display the gallery ( usually where you retrieve the model, such as a post.show.blade.php ).

<x-dropzone-gallery :model="$post"/>

If you want to associate other models to work with dropzone-uploader, just edit the migration file of the package, adding more models in the table, as in the example below:

/**
* Adding Tags and Categories
*/

$table->unsignedBigInteger('tag_id')->nullable();
$table->unsignedBigInteger('category_id')->nullable();

$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');

Publish components and assets in your application and customize as you wish.

php artisan vendor:publish --provider="Ewvlnet\Dropzone\DropzoneServiceProvider

📄 License

MIT

Follow ewvl.net ✌️ 👺 ✌️

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固