Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iki's avatar
Level 3

one to many relation not working

hey guys i have 3 tables

site_users

site_notifications

site__users__notifactions

in site__users__notifactions

i have user_id and notification_id

and i have a relation in the SiteUser Model as follow

public function get_notifications()

    {
        return $this->hasMany('App\Site_Users_Notifaction','user_id');
    }

when i try to call the relation in my blade like

@foreach($notifications as $notification)

{{dd($notification->get_notifications())}}

     @endforeach 

it gives me that error

Method Illuminate\Database\Query\Builder::get_notifications does not exist. (View: C:\xampp\htdocs\myspare\resources\views\site\notifications.blade.php)

and when i remove the () from the relation it gives null

0 likes
1 reply
iki's avatar
Level 3

it gives back a relation now after i added the same relation at the other other but it returns it empty

Please or to participate in this conversation.