当前位置:网站首页>laravel 使用 OSS时拼接 完整路径 及 laravel-admin 的多图片上传
laravel 使用 OSS时拼接 完整路径 及 laravel-admin 的多图片上传
2022-06-26 10:04:00 【siner.li】
在模型中添加(方法一)
protected static function boot()
{
parent::boot();
static::created(function ($modal) {
// 获取添加之后的字段值
$url = $modal->getAttribute('gwt');
$str = "https://www.baidu.com";
$new_url = $str . '/' . $url;
$modal->gwt = $new_url;
$modal->save();
});
}
在 form 中添加(方法二)
//把id通过隐藏域传入
$form->hidden('id');
$form->image('img', '图片')
$form->saved(function (Form $form){
// 判断是否有 https://www.baidu.com 字段
if(strpos($form->model()->img, 'https://www.baidu.com') === false){
$url = $form->model()->img;
$img = "https://www.baidu.com/".$url;
// 通过 use 引入 Contracts 模型
$info = Contracts::find($form->model()->id);
$info->img = $img;
$info->save();
}
});
上面时参考别的方法, 但是没有成功, 然后加了点代码.
使用 laravel-admin 多图/文件上传
拼接路径 – (不删图片)
// 模型中添加, setImgAttribute中间的Img即为字段名
public function setImgAttribute($value)
{
// 获取数组最后一个元素
$value[count($value)-1] = 'https://www.baidu.com/' . $value[count($value)-1];
// 限制 3 张图片
if (count($value) > 3) {
array_shift($value);
}
$this->attributes['img'] = implode(',', $value);
}
// getImgAttribute中间的Img即为字段名
public function getImgAttribute($value)
{
return explode(',', $value);
}
// 在 form 中使用 , 这里的 img 值为字段名
$form->multipleImage('img', '缩略图上传');
// 图片轮播
$grid->column('img', '图片')->carousel();
(删图片)
// 模型中添加, setImgAttribute中间的Img即为字段名
public function setImgAttribute($value)
{
if (count($value) == 0) {
$this->attributes['img'] = '';
return;
}
// 限制 3 张图片
if (count($value) > 3) {
array_shift($value);
}
// 获取数组每个元素
foreach ($value as &$v) {
if (strpos($v, 'https://www.baidu.com/')) === false) {
$v = 'https://www.baidu.com/' . $v;
}
}
$this->attributes['img'] = implode(',', $value);
}
// getImgAttribute中间的Img即为字段名
public function getImgAttribute($value)
{
return explode(',', $value);
}
// 在 form 中使用 , 这里的 img 值为字段名
$form->multipleImage('img', '缩略图上传')->removable();
// 图片轮播
$grid->column('img', '图片')->carousel();
边栏推荐
猜你喜欢

ISO 26262之——2功能安全概念

Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d

02-Redis数据结构之链表

Using reflection to export entity data to excel

携程机票 App KMM 跨端 KV 存储库 MMKV-Kotlin | 开源

Hazelnut cloud - SMS (tool)

【北邮果园微处理器设计】10 Serial Communication 串口通信笔记

nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
![[work details] March 18, 2020](/img/24/a72230daac08e7ec5bd57df08071f8.jpg)
[work details] March 18, 2020

MySQL 8th job
随机推荐
MySQL Performance Monitoring and SQL statements
MySQL 12th job - Application of stored procedure
OpenCV图像处理-灰度处理
Is it safe to open an account in the school of Finance and business?
【软件项目管理】期末复习知识点整理
Flutter与原生通信(上)
JS take the date of the previous month 【 pit filling 】
Which PHP open source works deserve attention
Expand and collapse too high div
Progressive web application PWA is the future of application development
Progressive Web 应用程序PWA是应用程序开发的未来
2、 Linear table
栖霞市住建局和消防救援大队开展消防安全培训
ISO 26262 - 2 functional safety concept
Opencv image processing - grayscale processing
滑动窗口
Easyexcel - Excel read / write tool
SQL Server foundation introduction collation
搜索引擎高级搜索方法记录
Fabric. JS upper dash, middle dash (strikethrough), underline