Skip to content
Advertisement

PHP Laravel – Get array of models by search or return empty array

Very new to PHP and Laravel so this is probably a noob question.

JavaScript

I know the $sites variable has content in it when I dd($sites); but when it comes to actually returning a value, I get nothing.

Any thoughts what I am doing wrong?

EDIT: The other function referenced above is here (shouldn’t really need it though).

JavaScript

dd($sites) results:

JavaScript

Advertisement

Answer

$sites is a Collection when $request->filled('name') is true.

When that’s the case, is_array($sites) will always return false since it is not an array but a Collection.

That’s why you fall into the return null part.

What you could check instead of is_array($sites):

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement