2 months ago

How Laravel chunks magic methods works?

Posted 2 months ago by Neeraj1005

basically i tried to understand how chunk methods works. can anyone tells me how it is works. I'm trying to fetch all record in my view blade but it returns nothing how to pass that chunk variable to blade?

 public function index()
        // $allCategory = Category::latest()->get();

        DB::table('categories')->orderBy('id')->chunk(10, function ($allCategory) {
            // foreach ($allCategory as $cat) {
            //     dd($cat);
            // }
            // dd($allCategory);
            return view('cms.categories.index',compact('allCategory'));


what I'm doing wrong can anyone explain me how to pass variable in blade or how to do this?

Please sign in or create an account to participate in this conversation.