0

Выполняю {{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 [▶]
    }
  ]
}
2
  • 2
    Читайте документацию, там несколько способов работы с методом contains
    – E_K
    20 мар 2020 в 11:32
  • Спасибо, не сразу заметил... 20 мар 2020 в 11:43

1 ответ 1

0

{{dump($collection-> whereIn('role_access', [5, 12]))}}

{{dump($collection-> whereIn('role_access', [5, 12]))->isNotEmpty()}}

но если честно это все костыли, RoleAccess::whereIn('role_access', [5,12])->exists();

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.