50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\UniformItem;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class StockDetailController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$term = trim((string) $request->query('search', ''));
|
|
|
|
return view('stock-details.index', [
|
|
'items' => UniformItem::with('variants')
|
|
->when($term, fn ($query) => $query->where(fn ($query) => $query
|
|
->where('name', 'like', "%{$term}%")
|
|
->orWhere('code', 'like', "%{$term}%")
|
|
->orWhere('material', 'like', "%{$term}%")
|
|
->orWhere('color', 'like', "%{$term}%")))
|
|
->orderBy('name')->paginate(10)->withQueryString(),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, UniformItem $uniformItem)
|
|
{
|
|
$data = $request->validate([
|
|
'material' => ['nullable', 'string', 'max:150'],
|
|
'color' => ['nullable', 'string', 'max:100'],
|
|
'care_instructions' => ['nullable', 'string', 'max:1000'],
|
|
'description' => ['nullable', 'string', 'max:1000'],
|
|
'front_image' => ['nullable', 'image', 'max:4096'],
|
|
'back_image' => ['nullable', 'image', 'max:4096'],
|
|
]);
|
|
|
|
foreach (['front_image', 'back_image'] as $field) {
|
|
if ($request->hasFile($field)) {
|
|
if ($uniformItem->{$field}) {
|
|
Storage::disk('public')->delete($uniformItem->{$field});
|
|
}
|
|
$data[$field] = $request->file($field)->store('uniforms', 'public');
|
|
}
|
|
}
|
|
$uniformItem->update($data);
|
|
|
|
return back()->with('success', "Details updated for {$uniformItem->name}.");
|
|
}
|
|
}
|