Relation Manager and HasManyThrough: General error: 1 no such column on one of the models
Hello everyone,
I'm building a library management system using filament and I'm trying to add relation manager to handle the intermediate tables that I need but I must be doing something wrong...
The error message is:
SQLSTATE[HY000]: General error: 1 no such column: chapters.chapter_story_id
I have a Chapter defined like this:
migration:
model:
And a Story defined like this:
migration:
model
And I have an intermediate table called ChapterStory:
migration:
model:
I haven't modified the relation manager:
Am I doing something wrong ?2 Replies
Your relationships is wrong. You don't need hasManyThrough, you structure looks to me like a belongsToMany. Get a grip on that first... That's Laravel 101, nothing to do with Filament.
Thanks for the reply, CORONEL!
I'm pretty new to Laravel, so that may be right. I'll check that more thoroughly and come back with more info or a solution 🙂
ok, managed to get something working;
Chapter -> belongsToMany Story using a custom pivot table (ChapterStory)
Story -> hasManyThrough Chapter using ChapterStory
This way the relation manager picks up on the chapters correctly.
I only have a problem using the ChapterStoryResource that has to do with the redirection that happens after a record is created:
Missing required parameter for [Route: filament.admin.resources.chapter-stories.edit] [URI: admin/chapter-stories/{record}/edit] [Missing parameter: record].
Creating the resource works fine and clicking on the table rows redirects to the correct edit view, the error only happens on create. Is this normal when extending the Pivot Eloquent class ?
got it! belongsToMany on both tables xD
but it doesn't solve the creation step redirection 😦