<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Str;

class UploadController extends Controller
{
    public function upload(Request $request)
    {
        $files = $request->allFiles();
        $newFiles = [];
        foreach ($files as $file) {
            if ($file instanceof UploadedFile) {
                $newFile = $file->move(public_path('images'), Str::random() . '.' . $file->extension());
                $newFiles[] = '/images/' . $newFile->getFilename();
            }
        }

        return [
            'urls' => $newFiles
        ];
    }
}
