jeudi 17 mars 2016

Larvel eloquent not returning proper Object

I have two models

Invoice
amount

The relationship is as follow

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');
    }

}

Now I am trying to retrieve the invoices with the payment like this

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

But I am getting the object like this when i dd() it

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
    }

You can see these part in the array that it should have the details from the table but it is just giving me count of the fields of the table,

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

Can any one let me know where could be the mistake.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire