laravel-datatables
laravel-datatables copied to clipboard
Invalid argument supplied for foreach() in Datatables.php (line 57)
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
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
masyaAllah, "php artisan config: cache" is the answer to my prayer.
just clear config cache of laravel. php artisan config:cache
this is working for me
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.
This issue was closed because it has been inactive for 7 days since being marked as stale.