Support the ongoing development of Laravel.io →
posted 3 months ago
Eloquent
Last updated by @pippuccio76 3 months ago.
0

To get the users related to an admin in Laravel, you can use the hasMany relationship method on the Admin model to define a one-to-many relationship with the User model.

In the Admin model:

public function users()
{
    return $this->hasMany(User::class, 'id_users');
}

then you can do in your view:

@if ($record->admin?->notifiche) // check if notifiche is not null
    {{ $record->admin->notifiche }}
@endif
1

Sign in to participate in this thread!

LaraJobs

Your banner here too?

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.

© 2023 Laravel.io - All rights reserved.