I'm facing strange case. I face an error in production env not while in dev it's working fine.
Development: Laravel 5.4.28 PHP 7.0.13 MYSQL 5.7.17
Production: Laravel 5.4.28 PHP 7.2.1 MYSQL 5.7.20
In implementation code. I used:
namespace App;
use Illuminate\Support\Facades\Storage;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
class Artwork extends Model
{
use Searchable;
In development it works fine. But in production it gives me this error: count(): Parameter must be an array or an object that implements Countable in Builder.php (line 936)
as you can see in this pic:
Any idea what is the reason behind this? and how to fix?
/Put this code at the beginning your routes file its will work fine/
place the below line ob code before the class name in your controllers
I was facing the same issue with an external created table (Not using migration or command), After creating the model, I just assigned a table name, but the problem was in my model
protected $fillable
where I assign string instead of array and error occurred. There is 2 possible solution for that.protected $fillable = ['filed1', 'filed2'];
protected $fillable
completely (Not Recommended)Model looking for countable parameter:
I was facing similar issue in Laravel 5.6. Where I was getting error for object based array. I knew that data in that particular variable will always remain object so i used to convert the object to array. Here is code sample:
$objectData = (array)$objectData; echo "Total Elements in array are: ".count($objectData);
'vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php' to: