laravel-admin tab选项卡上传图片

选项卡页面

<?php

namespace App\Admin\Controllers\SettingForm;

use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Facades\Storage;
use App\Admin\Models\AdminSetting;
use Cache;

class Pay extends Form
{
    public $title = '支付设置';
        
    public function handle(Request $request)
    {
        $data = $request->except('_token');
        $disk = Storage::disk('public');
        
        foreach($data as $name=>$value){
            $fileName = md5($name).'.'.$value->getClientOriginalExtension();
            $filepath = '/pay/'.$fileName;
            $bool = $disk->put($filepath, file_get_contents($value->getRealPath()));
            AdminSetting::set($name, '/uploads/'.$filepath);
        }
        AdminSetting::setcache();
        admin_success('','保存成功');
        return back();
    }
    public function form()
    {
        $this->image('alipay_qrcode', __('支付宝收款码'))->move('/alipay_qrcode/', \Str::random(7).'.jpg')->removable();
        $this->image('wechat_qrcode', __('微信收款码'))->move('/wechat_qrcode/', \Str::random(7).'.jpg')->removable();
    }
    public function data()
    {
        return [
            'alipay_qrcode'=> AdminSetting::get('alipay_qrcode'),
            'wechat_qrcode'=> AdminSetting::get('wechat_qrcode'),
        ];
    }
}
相关文章