For example, the structure of the table.
User
-id
-role_id
-fname
-lname
-country_code
-mobile
-password
-remember_token
-email
-address
-location_id
And another table
Role
-id
-name
Now, if I want all the user information from the user table with the role table, I will write like this.
$ user = User :: with ('Role') → where ('users.id', $ id) → first () → toArray ();
But it will retrieve all the data from the user table. I need selected columns of user table with active load. As soon as fname, lname, mobile, email from the user table and role_name from the role table.
I know how to select specific columns of a linked table as shown below.
public function Role(){
return $this->belongsTo('App\Role')->select('id','name as role_name');
}
But how to select specific columns of a user table using ()?