【问题标题】:Laravel eloquent not returning proper ObjectLaravel 雄辩不返回正确的对象
【发布时间】:2016-07-03 09:43:32
【问题描述】:

我有两个模型

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]

【问题讨论】:

    标签: arrays laravel-5 eloquent


    【解决方案1】:

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

    dd( $allinvoice[0] );
    

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

    【讨论】:

      猜你喜欢
      • 2020-02-18
      • 2017-01-26
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 2015-12-17
      • 2021-09-15
      • 2023-01-27
      • 2020-02-17
      相关资源
      最近更新 更多