Hi Team,
I’m encountering the following error when trying to fetch data using Laravel with MongoDB:
Call to a member function prepare() on null
Here are the steps I followed:
Installed the required MongoDB package (jenssegers/mongodb).
Updated the model file to use Jenssegers\Mongodb\Eloquent\Model as Eloquent.
Attempted to fetch data using the model.
Model File:
<?php namespace App\Models; use Jenssegers\Mongodb\Eloquent\Model as Eloquent; class Setting extends Eloquent { protected $connection = 'mongodb'; // Important! protected $fillable = ['type', 'description']; } **Controller Function:** function get_settings($type = "", $return_type = false) { $value = App\Models\Setting::where('type', $type); if ($value->count() > 0) { if ($return_type === true) { return json_decode($value->value('description'), true); } elseif ($return_type === "object") { return json_decode($value->value('description')); } else { return $value->value('description'); } } else { return false; } } Could you please assist me in resolving this issue?