I have two models Tour.php
and TourCategory.php
:
Tour.php
protected $table = `tours`;
public function category()
{
return $this->belongsTo('App\TourCategory');
}
TourCategory.php
protected $table = 'tcategories';
public function tours()
{
return $this->hasMany('App\Tour');
}
My db tables are as follows:
tours
table
id|title|category_id|content|
tcatgegories
table
id|name
And I have a view to show the all tours belonging to a category with the following code:
@foreach ($category->tours as $tour)
<tr>
<th>{{ $tour->id}}</th>
<td>{{ $tour->title}}</td>
<td>
<span class="label label-default">{{$category->name}}</span>
</td>
</tr>
@endforeach
With this above code I'm getting error of:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tours.tour_category_id' in
'where clause' (SQL: select * from `tours` where `tours`.`tour_category_id` = 1 and
`tours`.`tour_category_id` is not null) (View: F:\multiauth_tutorial-masteresources\
views\admin\categories\show.blade.php
I have used same code for my previous projects also but didn't had any errors. Or am I missing something ?