Answer the question
In order to leave comments, you need to log in
How to correctly set a checkbox for checkboxes?
The restaurant editing view has checkboxes with all payment methods, you must set checked for those used by the restaurant. How is it customary to solve such a problem in laravel, so as not to make a request in each iteration? Thank you.
Controller:
$restaurant = Restaurant::find($id)->load('payMethods');
$payMethods = PayMethods::all();
@foreach($payMethods as $payMethod)
<div class="custom-control custom-checkbox">
<input name="pay_method" type="checkbox">{{ $payMethod->name }}</label>
</div>
@endforeach
Answer the question
In order to leave comments, you need to log in
Something like $restaurant->payMethods->contains($payMethod)
https://laravel.com/docs/7.x/eloquent-collections#...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question