Я не могу отобразить отношения после того, как уже установил Eloquent Relationships в модели.
В модели: Art_obj
class Art_obj extends Model
{
protected $table = 'art_objs';
protected $fillable = ['Id_no','Artist','Year','Title','Description','Origin','Epoch','Picture','Type_of_art'];
public function Painting(){
return $this->hasOne(Painting::class,'Id_no');
}
}
В модели: Картина
class Painting extends Model
{
protected $table = 'paintings';
protected $fillable = ['art_obj_Id_no','Paint_type','Drawn_on','Style'];
public function Art_obj(){
return $this->belongsTo(Art_obj::class,'Id_no');
}
}
In PaintingController
public function index()
{
$paintings = Painting::with('Art_obj');
return view('ArtObj.Painting', compact('paintings'));
}
в Painting.blade.php
<table class="table table-bordered table-striped">
<tr>
<th>Title</th>
<th>Paint type</th>
<th>Drawn on</th>
<th>Style</th>
</tr>
@foreach($paintings as $row)
<tr>
<td>{{$row->Art_obj->Title}}</td>
<td>{{$row['Paint_type']}}</td>
<td>{{$row['Drawn_on']}}</td>
<td>{{$row['Style']}}</td>
</tr>
@endforeach
</table>
В поле зрения не отображается.
введите описание изображения здесь