There's a loan table and loan_addition table. How can I sum the added_amt of loan_addition table and show them while returning loan table data? loan_addition table
id loan_id added_amt
1 1 100
2 1 200
controller
$data = Loan::select('*')
->with('loanAddition') // how to sum all the columns of respective loan_id here
->get();
dd($data);
loan model
class Loan extends Model
{
public function loanAddition() {
return $this->hasMany(LoanAddition::class);
}
}
LoanAddition model
class LoanAddition extends Model
{
public function loan()
{ return $this->belongsTo(Loan::class); }
}
Thanks in advance..