Support the ongoing development of Laravel.io →
Database Eloquent

How can I validate it?

If I use:

$res = DB::table('estacaohs')
        ->whereRaw($sql)
        ->get();

if ($res->exists()) { /* do something */ }

It works when there are no rows, but when there are, it returns an array, and then this code throws an error since $result is an array and not a Collection.

Does Laravel offer any way to validate this?

Last updated 3 years ago.
0

Doesn't the query builder always return an array? So couldn't you just do this?

if (empty($res)) {
    // do something
}
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

resmall resmall Joined 24 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.