count must be an array or object [on hold]

127
April 15, 2019, at 06:10 AM

I just started learning laravel and I created a new blade called index.blade inside views/posts folder and inside it, I used @if(count($posts)>0) statement to show posts, however, it is showing:

count(): Parameter must be an array or an object that implements Countable (View: C:\xampp\htdocs\myApp\resources\views\Posts\index.blade.php)

How can I fix this?

Answer 1

Unsure what the value of $count is, but you may use is_countable() before count() to prevent incorrect types from being passed in:

if(is_countable($count) && count($count)>0){...}

It is worth noting that you should ensure that $count is of the right type before this point in your code.

Rent Charter Buses Company
READ ALSO
form is uploading to /tmp/phpHQ6U5X instead of newly set /var/www/html/upload_tmp

form is uploading to /tmp/phpHQ6U5X instead of newly set /var/www/html/upload_tmp

I am trying to upload files to my server through a CRUDI am having an issue moving the uploaded file to its new directory which exists

137
Access a file outside of root/htdocs on windows in PHP

Access a file outside of root/htdocs on windows in PHP

How can i access a file outside of htdocs folder on windows? I have a config file outside of my root (htdocs) folder, in which i want to save off the configuration for my database connection, but when i call it, it says no file found

142
Why isn't my php json_encode not serializable with .responseJSON in alamofire?

Why isn't my php json_encode not serializable with .responseJSON in alamofire?

I'm having some trouble with serialization on a JSON response on my iOS app from my server, its a PHP back-endMy app sends a post request with the appropriate parameters, validates them, puts the results in an array, and encodes it in

106