For the love of my sanity - HELP (POSTing checklist values from a form)
I feel like I could bang a brick off of my head for not being able to understand this.
I have a form that contains a checklist and I only want to pass through the checked values to my controller (obviously). Can I get it to work? No! It seems to pass through all values, even those not checked. Please PLEASE help.
Sure, because you're iterating over everything in $request ($tracks = $request;), instead of just the array(s) you sent. I can help a bit...but you'll have to fill in where $user and $token is coming from since you don't show it in your code (only show using them but not where it comes from)
$tracks = $request->trackid; //is an array containing only checked values
$tracknames = $reqeust->trackname; // is an array
$tracksources = $request->tracksource; // is an array
foreach ($tracks as $key => $trackId) {
Track::create([
'user_id' => $user->id,
'track_id' => $trackId,
'track_source' => $tracksources[$key],
'track_name' => $tracknames[$key],
'token' => $token,
]);
}