Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dflow opened this issue Apr 17, 2018 · 13 comments
Closed

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

dflow opened this issue Apr 17, 2018 · 13 comments

Comments

@dflow
Copy link

dflow commented Apr 17, 2018

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
@yajra
Copy link
Owner

yajra commented Apr 28, 2018

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?

@painter10
Copy link

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

@yajra
Copy link
Owner

yajra commented Jun 13, 2018

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

@painter10
Copy link

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.

@AmirKaftari
Copy link

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

@tepafril
Copy link

tepafril commented Feb 9, 2020

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

@rachmadbud
Copy link

rachmadbud commented Jul 7, 2020

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

@ambardws
Copy link

@AmirKaftari Masha Allah , thank you very much

@dea96
Copy link

dea96 commented Aug 3, 2020

@AmirKaftari thanks

@msalsabil
Copy link

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

@Dilshan97
Copy link

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

this is working for me

@github-actions
Copy link

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 github-actions bot added the stale label Sep 15, 2023
@github-actions
Copy link

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

@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants