[Solved] why nested loop not working in laravel

You have to make another array from your collection. And then you will able to get anything that you need. $result = []; foreach ($users as $u) { $result[ $u-> namecategory ] = $result[ $u-> namecategory ] ?? []; $result[ $u-> namecategory ][$namesubcategory] = $result[ $u-> namecategory ][$namesubcategory] ?? []; $result[ $u-> namecategory ][$namesubcategory][] = … Read more

[Solved] Writing a function in laravel

You’re really missing out on the best parts of Laravel’s query builder. public function jobsearch(Request $request) { // htmlspecialchars makes no sense here $keyword = $request->input(‘keyword’); $city_id = $request->input(‘city_id’); $category_id = $request->input(‘category_id’); $query = DB::table(‘job_details’); if($keyword) { $query->where(‘job_title’, ‘like’, ‘%’.$keyword.’%’); } if($city_id) { $query->where(‘city_id’, $city_id); } if($category_id) { $query->where(‘category_id’, $category_id); } $results = $query->get(); foreach($data … Read more