Level 102
You have a hasMany. So it has more than one tax
@foreach ($sch_bini_details->school_bini_tax as $t
{{$t->tax_topic}}
@endforeach
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I'm trying to Join two tables using Hasmany relation. But when i try to fetch data i got an error called Property does not exist. Here are my models and controller
Model
class school_bini extends Model
{
use HasFactory;
protected $table='_school_bini';
protected $fillable = [
'id',
'school_id',
'date',
'ab',
'behora',
'kriyakalap',
'debit_credit',
'debit_credit_type',
'sub_topic',
'summary',
'cash',
'completed',
];
public function school_bini_tax(): HasMany
{
return $this->hasMany(School_bini_tax::class, 'sch_bini_id', 'id');
}
class School_bini_tax extends Model
{
use HasFactory;
protected $table='_school_bini_tax';
protected $fillable = [
'tax_id',
'sch_bini_id',
'tax_topic',
'tax_cash',
];
public function sch_bini(): BelongsTo
{
return $this->belongsTo(school_bini::class);
}
}
controller
public function sch_bini_details($id)
{
$sch_bini_details = school_bini::with('school_bini_tax')->find($id);
return view('user.sch_bini_details', compact('sch_bini_details'));
}
view blade
<td>डे.{{$sch_bini_details->kriyakalap}}<br>क्रे.{{$sch_bini_details->school_bini_tax->tax_topic}}
You have a hasMany. So it has more than one tax
@foreach ($sch_bini_details->school_bini_tax as $t
{{$t->tax_topic}}
@endforeach
Please or to participate in this conversation.