Support the ongoing development of →
posted 5 years ago
Last updated 10 months ago.

Hello Amrshakya,

A lots of things in Laravel works automatically only when you follow the Laravel convention and eloquent relationships are on that breaks fast if you don't follow these simple conventions.

One problem that i see the code above per laravel convention is the naming of your models. Model names should be "singular" version of the table. e.g. Model: Navigation_group and Table: Navigation_groups better yet i would use camel casing (not pascal casing) for the model and snake case for the tables e.g. Model: navigationGroup Table: navigation_groups (with this type of naming laravel can work the magic very quickly"

Other things: your navigations_links table must have navigation_group_id (as foreign key) for this to automatically work or you must pass in as second parameter on relations to explicitly define the relationship the foreign field in navigation_links.

The final note to make your code work is, in your model, since you're not following the laravel convention for naming models than you must add protected class property $table and pass in the appropriate table name.

I hope this helps to resolve your issue. Please look at other developers code examples and follow community wide accepted convention for your code. it will make you better asset to the community and it will make your codes closer to standard ...


Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

amrshakya amrshakya Joined 9 May 2017


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.