1

I expanded Sentry users table with few columns, but in this case I need help for city_id column. I did it in Laravel migrations. Now I need to make relationship between Sentry users and cities table.

I try to expand Sentry user Model and add belongsTo, but I cannot use it from Sentry::findUserById() like Sentry::findUserById()->with('city')

How can I expand Sentry user model with relationship to another table/model?

Kolesar
  • 1,265
  • 3
  • 19
  • 41

1 Answers1

0
class User extends Eloquent {
    public function city() {
        return $this->hasOne('City', 'id', 'city_id');
    }
}

Then you should be able to do something like this in your controller

$city = User::find($id)->city->name;

Or in your view you can do

{{ $user->city->name }}
Nathan
  • 184
  • 2
  • 6