n+1
public function index(Request $request)
{
$search_query = $request->get('search');
$nebulizations = Nebulization::query();
if ($search_query){
$nebulizations->search($search_query);
}
$nebulizations = $nebulizations->with(['patient','nurse','medicineNebulizations'])->latest()->paginate(10)->withQueryString();
return view('nebulizations.index', compact('nebulizations'));
}
this gives me 10queries, and it takes 1s to load a single record. the medicine relations are coming from MedicineNebulization
6 Replies
can you share the @foreach on the
nebulizations/index.blade.php
template?Now the problem solved. But got more.
, how to load the old values from a dynamic input fields? here is the code.
I think I already replied to this one but again, you can use
{{ old('field_name') }}
to render the old value from a field. Is old('amount.0')
not loading the value?Not working
@foreach($nebulization->medicineNebulizations as $medicine_used)
<tr>
<td class="pl-4 w-[45%] py-2">
<select id="medicine"
name="medicine[]"
class="font-thin text-sm w-full p-2 border border-gray-200 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm">
@foreach( $medicines as $medicine )
<option value="{{ $medicine->id }}" @selected($medicine_used->id == $medicine->id)>{{ $medicine->name }}</option>
@endforeach
</select>
</td>
<td class="pl-4 w-[45%] py-2">
<input type="text" name="amount[]" value="{{ $medicine_used->amount }}"
placeholder="eg: 5m l, 3 gm, 5 ltr"
class="font-thin text-sm w-full p-2 border border-gray-200 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm">
</td>
This is the edit form
Its loading the amount correct
But the medicine
Can you share the definition of the Nebulization model class? I want to take a peek into the relationship names. Also, you can use three backticks (`) and the language name to share code with proper highlight, like this