string('stockable_type')->toString(); $stockableId = (int) $request->string('stockable_id')->toString(); $modelClass = match ($stockableType) { 'product-variant' => ProductVariant::class, 'raw-material-price' => RawMaterialPrice::class, default => abort(404, 'Tipe stok tidak valid.'), }; $stockable = $modelClass::with( $stockableType === 'product-variant' ? ['product', 'stockMutations.user.profile', 'stockMutations.source'] : ['rawMaterial', 'stockMutations.user.profile', 'stockMutations.source'] )->findOrFail($stockableId); $mutations = $stockable->stockMutations() ->with(['user.profile', 'source']) ->latest() ->paginate(50); $title = $stockableType === 'product-variant' ? "{$stockable->product?->name} - {$stockable->name}" : "{$stockable->rawMaterial?->name} - {$stockable->variant}"; return Inertia::render('admin/manage/stock/History', [ 'title' => $title, 'stockableType' => $stockableType, 'stockableId' => $stockable->id, 'mutations' => $mutations, ]); } }