1、直接上代码 使用$request->file() 获取路径 并上传到七牛云
<?php
namespace App\Admin\Actions\Pay;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use zgldh\QiniuStorage\QiniuStorage;
class ClickPublish extends RowAction
{
public $name = '上传';
public function handle(Model $model,$request)
{
$file = $request->file('pic');
$disk = QiniuStorage::disk('qiniu');
$fileName = md5($file->getClientOriginalName().time().rand()).'.'.$file->getClientOriginalExtension();
//上传截图
$bool = $disk->put('image/'.$fileName,file_get_contents($file->getRealPath()));
if($bool){
$img_path = 'image/'.$fileName;
//保存图片
$model->pic = $img_path;
$model->save();
}
return $this->response()->success('上传成功')->refresh();
}
public function form()
{
$this->image('pic', '收据')->value($this->row->pay_receipt);
}
}