Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

laravel - foreach() argument must be of type array|object, null given", exception: "ErrorException

I am trying to use data tables in laravel but getting below response:

{
    "message": "foreach() argument must be of type array|object, null given",
    "exception": "ErrorException",

I have tried this code in my controller:

$dataLists= DB::table("table_name")
                ->select('column_1', 'column_2')
                ->get();
return Datatables::of($dataLists)
            ->make(true);

If I print $datalists it display data in below formate

IlluminateSupportCollection Object
(
    [items:protected] => Array
        (
            [0] => stdClass Object
                (
                    [column_1] => 386932
                    [column_2] => data name 1
                )

            [1] => stdClass Object
                (
                    [column_1] => 8764358
                    [column_2] => data name 2
                )
        )
)

My php version is: 8.0.0 and laravel version is: 8.20.1

Can someone please help me to find out Where I am wrong?

question from:https://stackoverflow.com/questions/65878089/foreach-argument-must-be-of-type-arrayobject-null-given-exception-errore

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

just clear config cache of laravel
php artisan config:cache


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...