stripos()期望参数1为字符串,对象为laravel

时间:2020-09-28 16:44:58

标签: php laravel

代码

$data = Event::with(['favourite' => function ($q){
                        $q->select('*');
                        $q->groupBy(function ($date) {
                            return Carbon::parse($date->created_at)->format('M'); **// this line have error**
                        });
                    }])
                    ->select('id', 'title')
                    ->get()
                    ->where('id', $eventid)
                    ->toArray();

//如果不按数据分组,则输出将变为

 [0] => Array
            (
                [id] => 3
                [title] => Everything You Need to Know About Business From Start-up to IPO, Straight From the VC's Mouth
                [favourite] => Array
                    (
                        [0] => Array
                            (
                                [created_at] => 2020-09-10T17:54:06.000000Z
                            )
    
                        [1] => Array
                            (
                                [created_at] => 2020-09-10T18:21:00.000000Z
                            )
    
                        [2] => Array
                            (
                                [created_at] => 2020-09-28T15:05:38.000000Z
                            )
    
                        [3] => Array
                            (
                                [created_at] => 2020-08-28T15:05:38.000000Z
                            )
    
                    )
    
            )

最终数据应为

[0] => Array
        (
            [id] => 3
            [title] => Everything You Need to Know About Business From Start-up to IPO, Straight From the VC's Mouth
            [favourite] => Array
                (
                    [Aug] => Array
                        (
                            [total] => 1
                        )

                    [Sep] => Array
                        (
                            [total] => 3
    
                        )
                )

        )

有人遇到过此错误吗?当我尝试将数据分为一组时。如果将返回错误,则stripos()期望参数1为字符串,给定对象。上面的代码将从数据库返回所有数据。

0 个答案:

没有答案