Php 如果items.myfavorite返回not else false,则我想要items.myfavorite=true。我该怎么做

Php 如果items.myfavorite返回not else false,则我想要items.myfavorite=true。我该怎么做,php,laravel,eloquent,Php,Laravel,Eloquent,如果items.myfavorite返回not else false,则我想要items.myfavorite=true。我该怎么做呢?也许你可以用这个 $cat_query->with([ 'items' => function ($query) use($type, $id) { $query->where($type, $id)->with('image', 'addonCategory.addons', '

如果items.myfavorite返回not else false,则我想要items.myfavorite=true。我该怎么做呢?也许你可以用这个

     $cat_query->with([
          'items' => function ($query) use($type, $id) {
              $query->where($type, $id)->with('image', 'addonCategory.addons', 'reviews');
          },
          'items.myfavourite' => function ($query) use($user_id) {
              $query->where('user_id', $user_id);
          }
      ]);
    $cat_query->with([
        'items' => function ($query) use ($type, $id, $user_id) {
            $query->where($type, $id)
                ->with('image', 'addonCategory.addons', 'reviews')
                ->withCount(['myfavourite' => function ($query) use ($user_id) {
                    $query->select(DB::raw('IF(count(*) > 0, "true", "false")'))->where('user_id', $user_id);
                }]);
        }
    ]);