Laravel Eloquent: How to get only certain columns from joined tables

前端 未结 15 2499
礼貌的吻别
礼貌的吻别 2020-12-02 07:57

I have got 2 joined tables in Eloquent namely themes and users.

theme model:

public function user() {
  return $this->belongs_to(         


        
15条回答
  •  一向
    一向 (楼主)
    2020-12-02 08:35

    Another option is to make use of the $hidden property on the model to hide the columns you don't want to display. You can define this property on the fly or set defaults on your model.

    public static $hidden = array('password');
    

    Now the users password will be hidden when you return the JSON response.

    You can also set it on the fly in a similar manner.

    User::$hidden = array('password');
    

提交回复
热议问题