1

I am having issues with laravel 4 that did not happen with 3.

In the Permissions_Role model I have this relationship set up.

/**
 * User Relationship
 *
 * @return User
 */
 public function user()
 {
     return $this->belongsTo('User', 'user_id');
 }

Now, I want to use it later in the model to get that user's username. In laravel 3 this could be done with the following.

return ucword($this->user()->first()->username);

However, in four, it does not seem to return an object the same way and I can't seem to figure out the new syntax for it. Below is what I am trying currently.

/**
 * Get username
 *
 * @return string
 */
 public function getUsernameAttribute()
 {
     return ucwords($this->user()->first()->username);
 }

Any help on this would be greatly appreciated. Thanks :)

4

1 回答 1

1

你不必再写 () 了,它会自动转换成一个属性

新:$this->user->username代替$this->user()->username

于 2013-07-02T20:29:30.827 回答