feat: product screenshots gallery
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
bf365d029f
commit
a3894d2f37
@@ -223,6 +223,10 @@ class ProductController extends Controller
|
||||
'open_source' => 'boolean',
|
||||
'eu_hosted' => 'boolean',
|
||||
'eu_made' => 'boolean',
|
||||
'screenshots' => 'nullable|array',
|
||||
'screenshots.*' => 'image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'remove_screenshots' => 'nullable|array',
|
||||
'remove_screenshots.*' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -231,7 +235,24 @@ class ProductController extends Controller
|
||||
*/
|
||||
protected function syncDetails(Request $request, Product $product): void
|
||||
{
|
||||
//
|
||||
// Only rows belonging to this product may be removed
|
||||
$ids = array_filter((array) $request->input('remove_screenshots', []));
|
||||
if ($ids) {
|
||||
$product->screenshots()->whereIn('id', $ids)->get()->each(function ($shot) {
|
||||
Storage::disk('public')->delete($shot->path);
|
||||
$shot->delete();
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->hasFile('screenshots')) {
|
||||
$position = ($product->screenshots()->max('position') ?? -1) + 1;
|
||||
foreach ($request->file('screenshots') as $file) {
|
||||
$product->screenshots()->create([
|
||||
'path' => $file->store('screenshots', 'public'),
|
||||
'position' => $position++,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,6 +267,10 @@ class ProductController extends Controller
|
||||
Storage::disk('public')->delete($product->thumbnail);
|
||||
}
|
||||
|
||||
foreach ($product->screenshots as $shot) {
|
||||
Storage::disk('public')->delete($shot->path);
|
||||
}
|
||||
|
||||
$product->delete();
|
||||
|
||||
return redirect()->route('products.index')
|
||||
|
||||
Reference in New Issue
Block a user