Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
Solution

I don't know which model 'submenu' columns belongs to. If it belongs to Menu model:

$menus = Menu::whereHas('roles', function($q)
{
    $q->where('id', 4);
})->where('submenu', 0)->get();

If it belongs to Role model:

$menus = Menu::whereHas('roles', function($q)
{
    $q->where('id', 4)->where('submenu', 0);
})->get();
Last updated 2 years ago.
0

Thank you for your reply Stolz!

I'm still having problems though :/ .. the following problem is displaying:

*Navigation is the term used instead of Menu

Column not found: 1054 Unknown column 'roles.navigation_id' in 'where clause' (SQL: select * from navigations where (select count(*) from roles where roles.deleted_at is null and roles.navigation_id = navigations.id and id = 4 and roles.deleted_at is null) >= 1 and submenu = 0)

The following are the tables and their fields

navigations Table-- id, name, url, order, submenu

roles Table-- id, name, desc

navigation_role Table (pivot table)-- id, navigation_id, role_id

Last updated 2 years ago.
0

OK! managed to solve the issue :)

Stolz your code was right, my problem was that instead of using belongsToMany I was using hasMany, when declaring many to many relationship inside my models

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

xikky xikky Joined 30 Jun 2014

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.

© 2024 Laravel.io - All rights reserved.