ladybirdweb / faveo-helpdesk

Faveo Open source ticketing system build on Laravel framework
https://www.faveohelpdesk.com/online-demo/
Open Software License 3.0
1.15k stars 564 forks source link

Alert ! count(): Parameter must be an array or an object that implements Countable when creat ticket #3238

Open ese105 opened 4 years ago

ese105 commented 4 years ago

Description:

i got error

Alert ! ×count(): Parameter must be an array or an object that implements Countable

after submit new ticket without login.

Steps To Reproduce:

Downloaded from

AngeloPZcode commented 2 years ago

i have a same issue

pvi-github commented 1 year ago

Hello,

Same here with version 1.11.1 and PHP7.4

pvi-github commented 1 year ago

I think i found the origin of this problem. The PHP function count() did change between maybe PHP 7.1 and PHP 7.2... if the object you want to count is not "countable" (and null is NOT countable) it triggers an error.

There are maybe other places where count should be fixed but here is the minimum change i found to create a ticket :

diff --git a/app/Http/Controllers/Agent/helpdesk/TicketController.php b/app/Http/Controllers/Agent/helpdesk/TicketController.php
index 18d023c00..b30320007 100755
--- a/app/Http/Controllers/Agent/helpdesk/TicketController.php
+++ b/app/Http/Controllers/Agent/helpdesk/TicketController.php
@@ -144,7 +144,7 @@ class TicketController extends Controller
                     return Redirect()->back()->with($data)->withInput($request->except('password'));
                 } else {
                     $code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get();
-                    if (!count($code)) {
+                    if (!count(Array($code))) {
                         $data = [
                             'fails'              => Lang::get('lang.incorrect-country-code-error'),
                             'phonecode'          => $geoipcode->phonecode,
@@ -245,7 +245,7 @@ class TicketController extends Controller
         if (!$files) {
             return $size;
         }
-        if (count($files) > 0) {
+        if (count(Array($files)) > 0) {
             foreach ($files as $file) {
                 $size += $file->getSize();
             }
@@ -606,7 +606,7 @@ class TicketController extends Controller
     public function checkMobile($mobile)
     {
         $check = User::where('mobile', '=', $mobile)->first();
-        if (count($check) > 0) {
+        if (count(Array($check)) > 0) {
             return true;
         }

@@ -1763,7 +1763,7 @@ class TicketController extends Controller
                     foreach ($thread as $th_id) {
                         // echo $th_id->id." ";
                         $attachment = Ticket_attachments::where('thread_id', '=', $th_id->id)->get();
-                        if (count($attachment)) {
+                        if (count(Array($attachment))) {
                             foreach ($attachment as $a_id) {
                                 // echo $a_id->id . ' ';
                                 $attachment = Ticket_attachments::find($a_id->id);
@@ -2553,7 +2553,7 @@ class TicketController extends Controller
     {
         $attacment = [];
         if ($attach != null) {
-            $size = count($attach);
+            $size = count(Array($attach));
             for ($i = 0; $i < $size; $i++) {
                 $file_name = $attach[$i]->getClientOriginalName();
                 $file_path = $attach[$i]->getRealPath();
pvi-github commented 1 year ago

Nota : Maybe the last change is not totally necessary because of the if ($attach != null) { just before.

ese105 commented 1 year ago

Sorry this email person had passed away 7 month ago...

Please remove this email from your list...thank you

On Tue, 28 Feb 2023, 1:00 am PVi, @.***> wrote:

Nota : Maybe the last change is not totally necessary because of the if ($attach != null) { just before.

— Reply to this email directly, view it on GitHub https://github.com/ladybirdweb/faveo-helpdesk/issues/3238#issuecomment-1446696753, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNGZ7ZWH3FQC4TIHUKYABTWZTMT7ANCNFSM4LEBJ4IQ . You are receiving this because you authored the thread.Message ID: @.***>

bhanu2217 commented 1 year ago

Are you still facing this issue in Faveo v2.0.1 or later?