Laravel Collections search

Viewed 41

I have SQL query & sub query results and then convert these results to collection as bellow

$co=collect($users);

my collection array is as bellow

Illuminate\Support\Collection^ {#1984
  #items: array:4 [
    "id" => 92
    "user" => "abc"
     "created_at" => "2020-04-16T12:13:11.000000Z"
     "updated_at" => "2020-12-05T20:32:56.000000Z"
     "groups" => array:6 [
      0 => array:6 [
        "id" => 1
        "user_id" => 1
        "group_id" => 92
        "title" => "new group"
        "created_at" => "2020-04-16T12:13:11.000000Z"
        "updated_at" => "2020-12-05T20:32:56.000000Z"
    1 => array:6 [
        "id" => 1
        "user_id" => 1
        "group_id" => 91
        "title" => "other group"
        "created_at" => "2020-04-16T12:13:11.000000Z"
        "updated_at" => "2020-12-05T20:32:56.000000Z"

as you can see there is two columns with name of {id} , one in first array and other in sub array "groups"

I want to search the collection for ID and for title I am using these command but both are returning empty array.

$filtered = $co->where('id',1);
    dd($filtered);

also

$filtered = $co->where('title','new group');
     dd($filtered)

; or

 $filtered = $co->where('groups.title','new group');
     dd($filtered);

how to get these values

Thanks

0 Answers
Related