大家好我正在使用jessengers mongodb扩展,我已经有一个mongodb填充,问题是它显示了受保护的属性,我的代码是:
模型:
<?php
namespace App;
use Jenssegers\Mongodb\Model as Eloquent;
use \Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Pessoas extends Eloquent
{
public $guarded = ['password'];
public $fillable = ['nome'];
}
路由器
Route::get('/pessoas', function () {
$pessoas = \App\Pessoas::all();
dd($pessoas);
});
返回
0 => Pessoas {#147 ▼
+guarded: array:1 [▶] **<<<< 1 guarded**
+fillable: array:1 [▶] **<<<<<< 1 fillable**
#collection: null
#primaryKey: "_id"
#parentRelation: null
#connection: null
#table: null
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:27 [▶] **<<<<<<< 1 was expected or 26**
#original: array:27 [▶] **<<<<<< ok**
#relations: []
#hidden: []
#visible: []
#appends: []
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
答案 0 :(得分:0)
使用Jessengers Mongodb扩展的查询返回Collection
个对象。由于您要转储对象的值,因此您将看到对象的受保护属性和公共属性。为防止出现这种情况,您应该使用toArray()
对象上的Collection
方法。
Route::get('/pessoas', function () {
$pessoas = \App\Pessoas::all();
dd($pessoas->toArray());
});