php - Laravel Model is not getting data
I have created a model called MongodbServer and the database table name is mongodb_servers. Now when I want to get all the data using :
$MongodbServers = MongodbServer::get();
var_dump( $MongodbServers );
I am getting this error:
object(Illuminate\Database\Eloquent\Collection)#1065 (2) { ["items":protected]=> array(0) { } ["escapeWhenCastingToString":protected]=> bool(false) }
Is there anything I am doing wrong?
Answer
Solution:
That's not an error what you are posting. var_dump is describing the $MongodbServers variable. Here you can find more about it.
So as you can see in the dump your object is a Illuminate\Database\Eloquent\Collection. Now you could iterate through your items for example. For this you could use the following code snipet:
$MongodbServers->each(function ($item) {
// Some code
});
Here are more informations about the possibilities with an eloquent collection.
Edit: I just saw the "items":protected]=> array(0) in the dump what means that you don't have any entries in your db.