in my opinion it would be amazing if you could make a series about Laravel (5.1) and MongoDB. I played around with these two guys during the last few days but I don't really get a simplicity of Laravel and Eloquent like I would expect it.
In my opinion there are two packages which will help connecting a Laravel project with a MongoDB.
I'm in the same boat as you. I'm using Jenssenger's package. The way I found around it is to search through the parent class using the whereRaw method
class Car extends Eloquent
{
public static function findByID($id)
{
$showroom = Showroom::whereRaw(array('car._id' => new MongoId($id)))->first();
$car = $showroom->car->find($id);
return $car;
}
}
Whenever I need to search for a document that is embedded, I just used the findById() instead of find().
Yeah @iceheat I played around with this stuff and in my opinion you are also able to do things like this:
// Search in post comments ...
$posts = App\Post::where('comments.content', 'LIKE', '%temporibus%')->get();
// ... when you extend your post model like this
public function comments()
{
return $this->embedsMany('App\Comment');
}
hello sir.
im also on developing laravel 5.1 with mongodb.
i have a bit problem in auth and registring function. it said "ErrorException in Builder.php line 203".
i know maybe its related with the query that default authcontroller create. should i changed it completely? or there is a way to change the querybuilder?
Hello all, i've been unable to install the 'composer require jenssegers/mongodb' properly on windows. Added mongodb extension which is now showing in extensions list (not in phpinfo print). Still when i try to install jenssegers, i get following errors:
Your requirements could not be resolved to an installable set of packages.
Problem 1
I've got jenssegers/mongodb 3.1 installed with Laravel 5.3. My environment variables are setup, and my database is configured. I can use MongoDB outside of Laravel and all is fine, but when I enter something into a form in Laravel, the data is not persisted in the database. I don't know where the data is going. I've been stuck here for three days! Unfortunately, I've not found one comprehensive video on the internet for configuring MongoDB with Laravel demonstrating success.
Can anyone point me to a good Laravel/MongoDB tutorial?
@sharkreader if you're already talking about entering data into a form, you're probably getting too far ahead of yourself. I would start by testing to see if you can just create and save a MongoDB Eloquent record. Read the Laravel-MongoDB readme and start with creating a test model class, then see if you can save it (see the "Saving a new model" section).
@iceheat I was having a problem getting inner documents in a collection , your answer inspired me and worked for me thanks a lot
$userInvoices = user_invoice::whereRaw(array('user.$id' => new ObjectID($loggedInUser->_id)))->get();