2

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]

1 Answer 1

1

The debug out sometimes truncates the result if there are too may results or sub-arrays. To solve the issue, you should limit the dd() to a subset, e.g.

dd( $allinvoice[0] );

You should then be able to expand the sub-elements.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.