**`$result[$product->id] = $name;`**
Tam bu kısımda erişmek istediğim şey ProductOrder modelinde ki name değilde Orders modelinde ki drivers_name isimli alan buna tam olarak nasıl erişebilirim ?
İlişkim şu şekilde
public function orderExit()
{
return $this->belongsTo(Orders::class, 'orders_id');
}
Select::make('product_order_id')->label('Ürün Seçiniz')
->options(function () {
$barcodeNumbers = session('barcode_numbers');
if (session()->has('barcode_numbers')) {
$products = ProductOrder::query()
->select('id', 'name', 'amount')
->where('customer_id', Auth::user()->customer_id)
->where('warehouse_status', 1)
->whereIn('barcode_number', $barcodeNumbers)
->where('amount','>',0)
->get();
$groupedProducts = $products->groupBy('name')->map(function ($group) {
return $group->max('amount');
})->toArray();
$result = [];
foreach ($groupedProducts as $name => $maxAmount) {
$product = $products->where('name', $name)->where('amount', $maxAmount)->first();
if ($product) {
$result[$product->id] = $name;
}
}
return $result;
}
$products = ProductOrder::query()
->select('id', 'name', 'amount')
->where('customer_id', Auth::user()->customer_id)
->where('warehouse_status', 1)
->where('amount','>',0)
->get();
$groupedProducts = $products->groupBy('name')->map(function ($group) {
return $group->max('amount');
})->toArray();
$result = [];
foreach ($groupedProducts as $name => $maxAmount) {
$product = $products->where('name', $name)->where('amount', $maxAmount)->first();
if ($product) {
$result[$product->id] = $name;
}
}
return $result;
})
->required(),