Laravel雄辩不回归正确的对象

时间:2016-03-17 07:15:12

标签: arrays laravel-5 eloquent

我有两个型号

Invoice
amount

关系如下

namespace App;

use Illuminate\Database\Eloquent\Model;

class Invoice extends Model
{
    //
     protected $table = 'event_invoice';
     protected $primaryKey = 'Id';

    /*
     * An invoice can has many payments 
     *
     */
     public function payments(){
        return $this->hasMany('App\paymentrecieved');
    }

}

现在我正在尝试使用这样的付款检索发票

$allinvoice = Invoice::with(['payments', 'comments'])->where( DB::raw('year(DueDate)'), $year)->get();

但是当我dd()它

时,我得到了这样的对象
Collection {#1191 ▼
  #items: array:390 [▼
    0 => Invoice {#750 ▶}
    1 => Invoice {#751 ▶}
    2 => Invoice {#752 ▼
      #table: "event_invoice"
      #primaryKey: "Id"
      #connection: null
      #perPage: 15
      +incrementing: true
      +timestamps: true
      #attributes: array:38 [ …38]
      #original: array:38 [ …38]
      #relations: array:1 [ …1]
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [ …1]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
      +wasRecentlyCreated: false
    }

你可以在数组中看到这些部分应该有表中的详细信息,但它只是给我数了表的字段,

 #attributes: array:38 [ …38]
      #original: array:38 [ …38]
      #relations: array:1 [ …1]

1 个答案:

答案 0 :(得分:1)

如果结果或子数组太多,则调试有时会截断结果。要解决此问题,您应该将dd()限制为一个子集,例如

dd( $allinvoice[0] );

然后您应该能够扩展子元素。