ibekzod/uploader

具有数据库集成和动态文件结构的文件上传器

v1.0.2 2023-01-25 11:54 UTC

This package is auto-updated.

Last update: 2024-09-25 15:48:51 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

这是一个轻量级的文件上传包,包含上传服务和现成的API以及控制器

安装

您可以通过Composer安装此包

composer require ibekzod/uploader

使用Artisan发布包的配置文件(config/mediable.php)

php artisan vendor:publish --provider="IBekzod\Uploader\UploaderServiceProvider"

运行迁移以将所需的表添加到您的数据库中。

php artisan migrate

使用方法

将文件上传到服务器,并将其放置在名为"uploads"的文件系统磁盘目录下的"files"子目录或您自定义的引用类型

<?php
    use IBekzod\Uploader\Uploader;
    use IBekzod\Uploader\Models\Upload;
    use App\Models\Post;

    $upload = Uploader::uploadAttachment($request->file('attachment'))->getUpload();
    //Let's assume we have Post model with image_id column or file_id whatever name you can write
    $post = Post::create([
        'title'=>'Title',
        'body'=>'Body',
        'image_id'=>$upload->id //unsigned big integer is preferred
    ]);
    //This is optional if you want to find 
    $upload->relation='post';//or simply Post::class
    $upload->relation_id=$post->id;
    $upload->save();
    //By this way you can get all post images
    $allPostImages=Upload::where('relation', 'post')->get();
    //Or related first post image
    $postImage=Upload::where('relation', 'post')->where('relation_id', $post->id)->first();
    //You are free to design your structure by using Upload

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全性

如果您发现任何安全问题,请通过电子邮件erkinovbegzod.45@gmail.com报告,而不是使用问题跟踪器。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件