Hi! How do I properly update the slugs of all selected posts in a list?
When I use the code below, I get an error
"count(): Argument #1 ($value) must be of type Countable|array, string given"
public function onUpdateSlug() {
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
foreach ($checkedIds as $modelId) {
$data = News::whereIn('id', $modelId)->first();
$slug = $data->id .'-'.str_slug($data->name);
News::whereIn('id',$modelId)->update(['slug' => $slug]);
}
}
return $this->listRefresh();
}
If I remove “foreach”, the code will work but all checked news will have the same slug.