I've started to use Voyager and I'm facing problems with resolving relations. I receive an exception whenever I try to view/read a database entry that contains a many-to-many relation to another table.
I have 2 tables, tours and activities that are related via an m to n relation, and an intermediate table activity_tour. I've prepared the tables for voyager as mentioned in the docs.
Table tours:
id | title | someOtherStuff | activities
where id is a string.
Table activities
id | someOtherStuff | tours
id is a string again. In the BREAD-builder menu, I've added
{
"relationship": {
"key": "id",
"label": "title"
}
}
to the tours column of the activities table.
The Activity-Model contains the following method to resolve the relation
public function tours(){
return $this->belongsToMany(Tour::class, 'activity_tour');
}
Table activity_tour
activity_id | tour_id
I receive the following error, whenever I want to view a specific Activity-entry. The code-part that causes the exception can be found here (Corresponding file: vendor/tcg/voyager/resources/views/bread/read.blade.php - starting at line 51).
But whenever I want to edit an activity, all related tours are loaded and displayed correctly without any error.
Versions
- Database: 10.2.3-MariaDB Homebrew
- Laravel: 5.4
- Voyager: v0.11.10