laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

Invalid argument supplied for foreach() in Datatables.php (line 57)

Open dflow opened this issue 6 years ago • 11 comments

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

dflow avatar Apr 17 '18 16:04 dflow

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?

yajra avatar Apr 28 '18 02:04 yajra

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 avatar Jun 13 '18 21:06 painter10

@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.

yajra avatar Jun 13 '18 23:06 yajra

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.

painter10 avatar Jun 14 '18 17:06 painter10

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

AmirKaftari avatar Jan 01 '20 13:01 AmirKaftari

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

tepafril avatar Feb 09 '20 14:02 tepafril

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

rachmadbud avatar Jul 07 '20 10:07 rachmadbud

@AmirKaftari Masha Allah , thank you very much

ambardws avatar Jul 11 '20 13:07 ambardws

@AmirKaftari thanks

dea96 avatar Aug 03 '20 05:08 dea96

masyaAllah, "php artisan config: cache" is the answer to my prayer.

msalsabil avatar Jun 09 '21 09:06 msalsabil

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

this is working for me

Dilshan97 avatar Jul 06 '21 15:07 Dilshan97

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 15 '23 00:09 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Sep 23 '23 00:09 github-actions[bot]