<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class UploadController extends AdminController
{

    public function editor(Request $request)
    {
        $files = $request->file("image");

        if (empty($files)) {
            return response()->json(['errno' => 5, 'msg' => '请选择文件']);
        }

        foreach ($files as $file) {
            $path = $file->store(
                'editor/' . date('Y/m/d'),
                config('admin.upload.disk')
            );

            $data[] = Storage::disk(config('admin.upload.disk'))->url($path);
        }

        return ['errno' => 0, 'data' => $data];
    }
}
