У меня есть модели Member
, Loan
и Interestamount
.Loan
имеет hasMany
отношения с Interestamount
.Кажется, я не могу получить доступ к данным из Interestamount
.
Я могу показать ссуду id
и Interestamount
в блейде, но не могу отсортировать Interestamount
для данного Loan
.
LoanController.php
public function loanInterest($criteria){
//$loanData = Loan::all();
$loanData =Loan::findOrFail($criteria);
return view($this->_pagePath.'loan.loaninterest',compact('loanData'));
}
web.php
Route::any('loaninterest/{criteria?}','LoanController@loanInterest')
->name('loaninterest');
Loan.php
use Illuminate\Database\Eloquent\Model;
class Loan extends Model
{
protected $fillable = [
'amount',
'interest',
'status',
'duration',
'member_id',
'loan_type_id',
'interest_type_id',
'loan_payment_type_id'
];
// protected $appends = 'interest_amount
public function getInterestAmountAttribute()
{
return ($this->amount)/100 * $this->interest;
}
public function interestamount()
{
return $this->hasMany(InterestAmount::class,'loan_id','id');
}
}
InterestAmount.php
use Illuminate\Database\Eloquent\Model;
class InterestAmount extends Model
{
protected $fillable = ['interestamount'];
public function loan()
{
return $this->belongsTo(Loan::class,'loan_id','id');
}
}
loan Interest.blade.php
<tr>
<td>{{$loanData->member->name}}</td>
@foreach($loanData->interestamount() as $int)
<td>{{$int->interestamount}} </td>
@endforeach
</tr>
loan.blade.php
<a href="{{route('loaninterest', $loan->id) }}">Interest detail</a>