I want to use MongoDB in Laravel. This is my code inside of the controller:
public function create (Request $request) {
$m = new MongoClient();
$db = $m->selectDB("Laravel");
$collection = $db->selectCollection("Posts");
$document = array(
"Title" => $request->input('Title'),
"Publisher" => $request->input('Publisher')
);
$collection->insert($document);
}
But when I click "Submit", it gives me an error :
Fatal error: Class 'App\Http\Controllers\MongoClient' not found
I have run MongoDB Server and also Wamp and I have installed MongoDB and it's driver for PHP …
What is my mistake ? (I should say that I haven't done any config for Laravel by using MongoDB. Is it needed ?)
new \MongoClient()instead