当前位置:网站首页>Splicing full paths and uploading multiple pictures of laravel admin when laravel uses OSS
Splicing full paths and uploading multiple pictures of laravel admin when laravel uses OSS
2022-06-26 11:06:00 【siner. li】
Add... To the model ( Method 1 )
protected static function boot()
{
parent::boot();
static::created(function ($modal) {
// Get the field value after adding
$url = $modal->getAttribute('gwt');
$str = "https://www.baidu.com";
$new_url = $str . '/' . $url;
$modal->gwt = $new_url;
$modal->save();
});
}
stay form Add ( Method 2 )
// hold id Incoming via hidden domain
$form->hidden('id');
$form->image('img', ' picture ')
$form->saved(function (Form $form){
// To determine if there is https://www.baidu.com Field
if(strpos($form->model()->img, 'https://www.baidu.com') === false){
$url = $form->model()->img;
$img = "https://www.baidu.com/".$url;
// adopt use introduce Contracts Model
$info = Contracts::find($form->model()->id);
$info->img = $img;
$info->save();
}
});
Refer to other methods above , But it didn't work , And then add some code .
Use laravel-admin More pictures / Upload files
Splicing path – ( Do not delete pictures )
// Add... To the model , setImgAttribute In the middle of the Img This is the field name
public function setImgAttribute($value)
{
// Get the last element of the array
$value[count($value)-1] = 'https://www.baidu.com/' . $value[count($value)-1];
// Limit 3 A picture
if (count($value) > 3) {
array_shift($value);
}
$this->attributes['img'] = implode(',', $value);
}
// getImgAttribute In the middle of the Img This is the field name
public function getImgAttribute($value)
{
return explode(',', $value);
}
// stay form Use in , there img The value is the field name
$form->multipleImage('img', ' Thumbnail upload ');
// Picture carousel
$grid->column('img', ' picture ')->carousel();
( Delete pictures )
// Add... To the model , setImgAttribute In the middle of the Img This is the field name
public function setImgAttribute($value)
{
if (count($value) == 0) {
$this->attributes['img'] = '';
return;
}
// Limit 3 A picture
if (count($value) > 3) {
array_shift($value);
}
// Get each element of the array
foreach ($value as &$v) {
if (strpos($v, 'https://www.baidu.com/')) === false) {
$v = 'https://www.baidu.com/' . $v;
}
}
$this->attributes['img'] = implode(',', $value);
}
// getImgAttribute In the middle of the Img This is the field name
public function getImgAttribute($value)
{
return explode(',', $value);
}
// stay form Use in , there img The value is the field name
$form->multipleImage('img', ' Thumbnail upload ')->removable();
// Picture carousel
$grid->column('img', ' picture ')->carousel();
边栏推荐
- JWT (SSO scheme) + three ways of identity authentication
- 2、 Linear table
- Code specification & explain in detail the functions and uses of husky, prettier, eslint and lint staged
- April 13, 2021 interview with beaver family
- 你好!正向代理!
- [deep learning theory] (6) recurrent neural network RNN
- [Beiyou orchard microprocessor design] 10 serial communication serial communication notes
- PC QQ大厅 上传更新 修改versionInfo
- mysql性能監控和sql語句
- Redis (basic) - learning notes
猜你喜欢

Fabric.js 上划线、中划线(删除线)、下划线
![[Beiyou orchard microprocessor design] 10 serial communication serial communication notes](/img/61/b4cfb0500bbe39ed6a371bb8672a2f.png)
[Beiyou orchard microprocessor design] 10 serial communication serial communication notes
![[work details] March 18, 2020](/img/24/a72230daac08e7ec5bd57df08071f8.jpg)
[work details] March 18, 2020

Nuxt. JS - learning notes

Grain Mall - distributed Foundation

Redis knowledge mind map

Easyexcel - Excel read / write tool

That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade

Idea remote debugger

matlab 编程实例: 如何统计元胞数组中元素的数量
随机推荐
UDP flood attack defense principle
consul微服务治理中心踩坑
ceph运维常用指令
(Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程
The difference between NPM and yarn
Redis (basic) - learning notes
redux相关用法
Laravel-admin 登录添加图形验证码
AIX basic operation record
[online simulation] Arduino uno PWM controls the speed of DC motor
LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路
Pit record_ TreeSet custom sorting results in less data loss
Getting started with postman
最牛X的CMDB系统
Postman入门教程
代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
laravel中使用group by分组并查询数量
laravel 写原生SQL语句
机器学习聚类——实验报告
Opencv image processing - grayscale processing