Support the ongoing development of Laravel.io →
Database Eloquent Blade
Last updated 1 year ago.
0

here's how my role and user model looks

// Role.php

public function user()
{
  return $this->hasMany('App\Role');
}

// User.php
public function role()
{
  return $this->belongsTo('App\User');
}

// get all users
$users = User::get();
foreach ($users as $user)
{
  echo $user->role->name;
}

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Niiwill niiwill Joined 24 Jun 2015

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.