Laravel: find out if variable is collection

You can try something like this

if(is_a($images, 'Illuminate\Database\Eloquent\Collection')) {
    ....do whatever for a collection....
} else {
    ....do whatever for not a collection....
}

Or

if ($images instanceof \Illuminate\Database\Eloquent\Collection) {
    ....do whatever for a collection....
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)