You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let me explain the use case first:
I want to be able to edit a form with a table with rows of checkboxes. How can I checked the selected items based on what is stored in my database?
Here are my controller:
// called from Datatables AJAX
public function getEditServiceItemList(Request $request, $id)
{
if ($request->ajax()) {
$items = Item::latest()->get();
$service = Service::find($id);
// foreach($service->serviceItems as $serviceItem)
return Datatables::of($items)
->addIndexColumn()
->addColumn('checkbox', function ($row) {
$checkbox = "<input type='checkbox' name='items[]' value='$row->id'>";
return $checkbox;
})
->rawColumns(['checkbox'])
->make(true);
}
}
// call from browser GET
public function edit($id)
{
$service = Service::find($id);
$sites = Site::get(["name", "id", 'zone']);
$engineers = User::whereHas(
'roles',
function ($q) {
$q->where('name', 'Engineer');
}
)->get();
return view('services.edit', compact('sites', 'engineers', 'service'));
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Let me explain the use case first:
I want to be able to edit a form with a table with rows of checkboxes. How can I checked the selected items based on what is stored in my database?
Here are my controller:
Here's my Datatables AJAX:
HTML table:
Beta Was this translation helpful? Give feedback.
All reactions