- 基础环境:Docker 部署配置,源码挂载实时同步 - 修复:super_admin 权限补全、登录重定向循环 - 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单) - 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单) - 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单) - 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器 - 各平台独立表结构和视图,互不影响
64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Plank\Mediable\Mediable;
|
|
|
|
/**
|
|
* Mediable Trait.
|
|
*
|
|
* Provides functionality for attaching media to an eloquent model.
|
|
*
|
|
* @author Sean Fraser <sean@plankdesign.com>
|
|
*
|
|
* Whether the model should automatically reload its media relationship after modification.
|
|
*/
|
|
trait Media
|
|
{
|
|
use Mediable;
|
|
|
|
/**
|
|
* Relationship for all attached media.
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
|
|
*/
|
|
public function media()
|
|
{
|
|
$media = $this->morphToMany(config('mediable.model'), 'mediable')
|
|
->withPivot('tag', 'order')
|
|
->orderBy('order');
|
|
|
|
// Skip deleted media if not detached
|
|
if (config('mediable.detach_on_soft_delete') == false) {
|
|
$media->whereNull('deleted_at');
|
|
}
|
|
|
|
return $media;
|
|
}
|
|
|
|
public function attachMedia($media, $tags): void
|
|
{
|
|
$tags = (array)$tags;
|
|
$increments = $this->getOrderValueForTags($tags);
|
|
|
|
$ids = $this->extractPrimaryIds($media);
|
|
|
|
foreach ($tags as $tag) {
|
|
$attach = [];
|
|
|
|
foreach ($ids as $id) {
|
|
$attach[$id] = [
|
|
'company_id' => company_id(),
|
|
'created_from' => source_name(),
|
|
'created_by' => user_id(),
|
|
'tag' => $tag,
|
|
'order' => ++$increments[$tag],
|
|
];
|
|
}
|
|
|
|
$this->media()->attach($attach);
|
|
}
|
|
|
|
$this->markMediaDirty($tags);
|
|
}
|
|
}
|