承接 akanaan/model-files 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

akanaan/model-files

Composer 安装命令:

composer require akanaan/model-files

包简介

A package for laravel to help attaching files to models (images, pdfs, ... etc).

README 文档

README

A package for laravel to help attaching files to models (images, pdfs, ... etc).

Installation

Use the package manager composer to install Laravel Model Files.

composer require akanaan/model-files

Run migrate to create tables

php artisan migrate

Usage

The package is very easy to use, just add the trait HasFiles to the model and create settings array for the files

<?php

namespace App\Models;

use AKanaan\ModelFiles\Traits\HasFiles;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasFiles;

    protected $attaches = [
        'logo' => [
            'disk' => 'public',
            'path' => '/',
        ],
        'images' => [
            'disk' => 'public',
            'path' => 'images',
        ]
    ];
}

Attach, Detach, Retrieve.

attaching

<?php
...
$product = Product::findOrFail($id);

$product->attachFile('logo', $request->file('logo'));
$product->attachFiles('images', [
    $request->file('images.0'),
    $request->file('images.1'),
    $request->file('images.2')
    ...
]);
...

detaching

<?php
...
$product = Product::findOrFail($id);

$product->detachFile('logo');
/*
 * Second param is optional (array of ids of files you want to delete)
 */
$product->detachFiles('images', [1, 2, 3]);
...

retrieving

<?php
...
$product = Product::findOrFail($id);

// returns instance of AKanaan\ModelFiles\Models\File
$product->retrieveFile('logo');
// returns collection of AKanaan\ModelFiles\Models\File
$product->retrieveFiles('images');
...

Public Url

<?php
...
$product = Product::findOrFail($id);

$logo = $product->retrieveFile('logo');
$publicUrl = $logo->url();
...

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固