Files
getgreen-backend/app/Jobs/Dashboard/Product/Screen.php
2026-04-28 16:00:18 +05:00

58 lines
1.4 KiB
PHP
Executable File

<?php
namespace App\Jobs\Dashboard\Product;
use App\Support\Uploads;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use App\Models\Screen as Screens;
use App\Api\ImageResize;
use Illuminate\Support\Facades\Storage;
class Screen
{
protected $request;
protected $id;
protected $img;
/**
* Screen constructor.
* @param $request
* @param $id
*/
public function __construct($request, $id)
{
$this->request = $request;
$this->id = $id;
$this->img = new ImageResize();
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
foreach ($this->request as $screen) {
$folder = Carbon::now()->format('Y/m/d');
// 1. Store original (S3 if enabled)
$path = Uploads::store($screen, "uploads/screens/original/{$folder}");
// 2. Local temp for resizing
$tempPath = Uploads::store($screen, 'temp', 'public');
$thumb = $this->img->resize($tempPath, 350, 'screens', true);
$screens = new Screens();
$screens->name = basename($path);
$screens->path = $path;
$screens->path_thumb = $thumb;
$screens->size = Storage::size($path);
$screens->product_id = $this->id;
$screens->save();
}
}
}