Как проверить содержит ли коллекция указанное значение?
Выполняю {{dump($collection->contains(12))}} - возвращает false
Как проверить содержит ли коллекция значения role_access = 5 или 12 ?
Illuminate\Database\Eloquent\Collection {#523 ▼
#items: array:2 [▼
0 => App\RoleAccess {#545 ▼
#connection: "mysql"
#table: "role_accesses"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:3 [▼
"role_id" => 1
"role_access" => 5
"name" => "Главный тренер"
]
#original: array:3 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
1 => App\RoleAccess {#546 ▼
#connection: "mysql"
#table: "role_accesses"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:3 [▼
"role_id" => 1
"role_access" => 12
"name" => "Администратор"
]
#original: array:3 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
]
}
Ответы (1 шт):
Автор решения: Bohdan Petrenko
→ Ссылка
{{dump($collection-> whereIn('role_access', [5, 12]))}}
{{dump($collection-> whereIn('role_access', [5, 12]))->isNotEmpty()}}
но если честно это все костыли, RoleAccess::whereIn('role_access', [5,12])->exists();