该集合实例上不存在属性ID

时间:2019-01-21 06:57:30

标签: laravel

我想在响应中添加Interest_status键。但显示我错误。这是我的代码。请帮忙。提前致谢。

    $activities_status = [];

    $activities = [];

    foreach ($activitiesDetail as $activityDetail) { 

        $activity = '';

        if(in_array($activityDetail->user_id, $userFriendIds))

        {

            $activity = Activity::where('id', $activityDetail->id)->with('joins')->get();


        } 

        else {

            $activity = Activity::where('id', $activityDetail->id)
                ->where('activity_privacy_visible', 0)->with('joins')->get();

        }

        $interest = $authUser->interests()->where('activity_id', $activity->id)->first();


            if($interest)

            {

                $status['interest_status'] = $interest->status;

                $activities_status[] = array_merge($status, $activity->toArray());


            } else {

                $status['interest_status'] = NULL;

                $activities_status[] = array_merge($status, $activity->toArray());


            }

        $activities = array_merge($activities, $activities_status);
    }
    return response()->json(['filter'=> $activities], 200);

如果我打印Interest_status,它会为我提供status的值,但我会返回整个显示错误的响应。请帮助。

0 个答案:

没有答案