Laravel-datatables: Invalid argument supplied for foreach() in Datatables.php (line 57)

Created on 17 Apr 2018  ·  9Comments  ·  Source: yajra/laravel-datatables

Summary of problem or feature request

getting error when call anyData Route. through the network inspector, I cleared php artisan cache.

ErrorException Invalid argument supplied for foreach()

in Datatables.php (line 57)

Code snippet of problem

Routes:

Route::get('/datatable','DatatablesController@getIndex');
Route::get('/anyData','DatatablesController@anyData')->name('datatables.data');

<?php

namespace App\Http\Controllers;


use Yajra\Datatables\Datatables;
use Illuminate\Support\Facades\DB;

class DatatablesController extends Controller
{
    /**
     * Displays datatables front end view
     *
     * @return \Illuminate\View\View
     */
    public function getIndex()
    {
        return view('reports.testdatatable');
    }

    /**
     * Process datatables ajax request.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function anyData()
    {
       return Datatables::of(User::query())->make(true);
    }

}

System details

  • Operating System MAC OS 10.11
  • PHP Version 7.2
  • Laravel Version 5.4
  • Laravel-Datatables Version 7.3
need feedback question

Most helpful comment

just clear config cache of laravel.
php artisan config:cache

All 9 comments

Your code looks fine. However, it seems like your version may not be updated? Datatables.php is for v6.0 below afaik? Please double check that you have the correct version?

Im facing same issue.

I've just upgraded to version 8, with:
composer require yajra/laravel-datatables-oracle:8.*
php artisan vendor:publish --tag=datatables --force

but Im still getting the error:

ErrorException in DataTables.php line 51:
Invalid argument supplied for foreach()

Please advise

@painter10 base on error log line 51, the new datatables.php config might not be overwritten. Maybe try deleting the config manually then publish again.

$builders = config('datatables.builders');
...
foreach ($builders as $class => $engine) {...

Also see https://yajrabox.com/docs/laravel-datatables/master/upgrade if you haven't checked it yet.

Thanks for suggestion. I think the problem was that I followed the Quick Start tutorial literally, so it was necessary to modify the setup, namely:
I had to delete config.php file in Bootstrap/cache, then in the config/app.php I changed
from:
Yajra\Datatables\DataTablesServiceProvider::class,
to:
Yajra\DataTables\DataTablesServiceProvider::class,
and now anyData() seems to work.
However, Im still struggling to display records in the datatable. Only headers are visible.

just clear config cache of laravel.
php artisan config:cache

@AmirKaftari I could resolve the issue by clearing laravel cache. Thank you!

@AmirKaftari All praise is due to Allah, the problem I'm finished with "php artisan config: cache"
Thank you to all of you..

@AmirKaftari Masha Allah , thank you very much

@AmirKaftari thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmadbadpey picture ahmadbadpey  ·  3Comments

FilipeBorges1993 picture FilipeBorges1993  ·  3Comments

Mopster picture Mopster  ·  3Comments

techguydev picture techguydev  ·  3Comments

Abdulhmid picture Abdulhmid  ·  3Comments