Support the ongoing development of Laravel.io →
posted 5 years ago
Eloquent
Last updated 6 months ago.
0

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 ...

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

amrshakya amrshakya Joined 9 May 2017

Moderators

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

Your logo here?

Laravel.io

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

© 2022 Laravel.io - All rights reserved.