pfrug/file-upload 问题修复 & 功能扩展

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

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

pfrug/file-upload

最新稳定版本:v1.0.0

Composer 安装命令:

composer require pfrug/file-upload

包简介

Trait to manage the upload images in laravel models

README 文档

README

Trait to simplify uploading images in Laravel

Installation

composer require pfrug/file-upload 1.0
// config/app.php
'providers' => [
    ...
    Pfrug\FileUpload\FileUploadServiceProvider::class,
];

Usage

Implement HasImageUploads in you model
Specify the fields that are of type file

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Pfrug\FileUpload\Traits\HasImageUploads;

class Post extends Model
{
    use HasImageUploads;

    protected $uploadableImages = [
        'image',
        'thumb'
    ];

In the controller it is not necessary to specify anything.
Only using the fill or create method the image will be saved correctly

public function store(Request $request)
{    
    // ... you code here, try-catch validate etc..
    Post::create($request->all());
    ...


public function update(Request $request, Post $post)
    // ... you code here, try-catch, validate data, etc..
    $post->fill($request->all());
    $post->save();

Or use direct assign

$post->title = $request->title ;
$post->image = $request->file('image');
$post->save();

Views

If you wish you can use the default view

    @include('fileupload::imageField', [
            'item' => $post,
            'field' => 'image',
            'cant_delete' => true
        ])

Configuration

php artisan vendor:publish --tag="fileupload-assets" --provider="Pfrug\FileUpload\FileUploadServiceProvider"
php artisan vendor:publish --tag="fileupload-lang" --provider="Pfrug\FileUpload\FileUploadServiceProvider"
php artisan vendor:publish --tag="fileupload-views" --provider="Pfrug\FileUpload\FileUploadServiceProvider"

This commands create files to:

"fileupload-assets"
{project}resources/css/vendor/fileupload/file-upload.css
{project}resources/js/vendor/fileupload/file-upload.js
{project}resources/img/vendor/fileupload/default.png

"fileupload-lang"
{project}resources/lang/{en-es}/fileupload.php

"fileupload-views"
{project}resources/view/vendor/fileupload/imageField.blade.php

Image storage

The images will be saved inside the folder storage/app/public/{model}
It is important to create a symbolic link, this can be done using the command php artisan storage:link

The path of the file will be stored in the database, so it is recommended that it be a field of type varchar(100)
ex: posts/9c744648c08730cd850c4d7dad9b998d.jpg

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-27