Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrizk's avatar
Level 1

Parameter must be an array or an object that implements Countable :Laravel.log

I'm running a streaming website on Laravel. I have changed some permissions to some pages to enable the admin upload of some media. I had also configured php.ini to change upload limit. All worked fine until I enter the UI as a logged user and when I click on a link that is suppose to send me to a user.blade that is a child of the master user.blade the page loads the redirect back the to dashboard. I received this error on Laravel.log

Next ErrorException: count(): Parameter must be an array or an object that implements Countable (View: /var/www/html/resources/views/user/single-video.blade.php) in /var/www/html/storage/framework/views/5c4244f87d80a74a83ff85808c78884f1a852ddf.php:132

The stack trace is showing the following:

Stack trace: #0 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(44): Illuminate\View\Engines\CompilerEngine->handleViewException() #1 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath() #2 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get() #3 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents() #4 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents() #5 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Response.php(53): Illuminate\View\View->render() #6 /var/www/html/vendor/symfony/http-foundation/Response.php(201): Illuminate\Http\Response->setContent() #7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1085): Symfony\Component\HttpFoundation\Response->__construct() #8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(94): Illuminate\Routing\Router->prepareResponse() #9 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing{closure}() #10 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func() #11 /var/www/html/app/Http/Middleware/Authenticate.php(28): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #12 [internal function]: App\Http\Middleware\Authenticate->handle() #13 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #16 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #17 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func() #18 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(96): Illuminate\Pipeline\Pipeline->then() #19 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(54): Illuminate\Routing\ControllerDispatcher->callWithinStack() #20 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(175): Illuminate\Routing\ControllerDispatcher->dispatch() #21 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(141): Illuminate\Routing\Route->runController() #22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(724): Illuminate\Routing\Route->run() #23 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}() #24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func() #25 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #26 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle() #27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #28 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #29 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #30 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #31 [internal function]: Illuminate\Session\Middleware\StartSession->handle() #32 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #33 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #34 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #35 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #36 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle() #37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #38 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #39 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #40 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #41 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle() #42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #43 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #44 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #45 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #46 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func() #47 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then() #48 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(699): Illuminate\Routing\Router->runRouteWithinStack() #49 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->dispatchToRoute() #50 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(246): Illuminate\Routing\Router->dispatch() #51 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}() #52 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func() #53 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #54 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() #55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array() #56 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #57 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func() #58 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() #59 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func() #60 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\Pipeline\Pipeline->then() #61 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() #62 /var/www/html/index.php(53): Illuminate\Foundation\Http\Kernel->handle() #63 {main}

I hope someone can tell me if this is the result of a code bug or just permissions issue. Any suggestion is welcome :))

0 likes
7 replies
Snapey's avatar

So, what are you counting in that part of the view?

jrizk's avatar
Level 1

its counting the below. but the error seems to be coming from the wishlist:

@if(count($wishlist_status) == 1)
@if(count($comments) > 0)
@if($video_imagess->count() == 0)
@if($video_images->count() == 0)
var comment_count = 0;
var count = 0;
comment_count = jQuery('#comment_count').text();
var count = parseInt(comment_count) + 1;
jQuery('#comment_count').text(count);
jQuery('#video_comment_count').text(count);

I tried commenting out the wishlist code in /var/www/html/storage/framework/views/5c4244f87d80a74a83ff85808c78884f1a852ddf.php and single/blade.php but still, the problem persists

Snapey's avatar

comment it in your blade file, not the cached version. Also, use blade comments not html ones

Which specific line is it?

Also, whats with all the @if statements with no @endif?

rodrigo.pedra's avatar

Did you change PHP versions? PHP 7.2 changed how the count functions work with uncountable values.

Reference:

https://wiki.php.net/rfc/counting_non_countables

Try using the null coalesce operator to make sure you have a countable value and not null, for example:

@if(count($wishlist_status ?? []) == 1)

I am in mobile right now, it is hard to give more examples

jrizk's avatar
Level 1

I'm on php7.4 tried the above. same error on UI. laravel.log gave the below :

Next ErrorException: Parse error: syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) (View: /var/www/html/resources/views/user/single-video.blade.php) in /var/www/html/storage/framework/views/5c4244f87d80a74a83ff85808c78884f1a852ddf.php:625
jrizk's avatar
Level 1

yes I did both

@if and @endif is for registered users and guests. it continues to @else direct to login modal

Snapey's avatar

Your current error is because of all those unterminated @if statements.

@if(count($wishlist_status) == 1)
@if(count($comments) > 0)
@if($video_imagess->count() == 0)
@if($video_images->count() == 0)

you now have 4 nested if statements and would need four @endif statements to unwrap it.

@endif 
@endif 
@endif 
@endif 

You cannot do this with a single @else or @endif

Please or to participate in this conversation.