TextInputColumn::make('stock_count') ->label('Stock Count') ->visible(request()->has('merchant_id')) ->default(function ($record) { // at the moment we get the first variant $variant_id = $record->variants()->first()->id; // lazy load 2 levels. $stocks = $record->variants()->where('id', $variant_id)->first()->merchants()->where('merchant_store_id', request()->get('merchant_id'))->first();return $stocks ? $stocks->pivot->stock_count : 0;})->label('Stock Count')