How to use laravel ORM even Table check flexibly

    class User extends Model{
    public function Roles()
        {
            return $this->hasOne("App\Role", "user_id", "id");
        }
    }
    
    class Message extends Model{
    public function User()
        {
            return $this->belongsTo("App\User", "user_id", "id");
        }
    }
    //Controller sql
    \DB::listen(function($sql,$binds){
        dump($sql,$binds);
    });
    
    $role = User::find(1)->Roles;//
    
    $mess = Message::with("User")->where("type",$type)->get();

similar to the query above, $role = User::find (1)-> Roles only finds the data of roles. If I want to query several fields of user and all (part of) fields of roles, how to write this orm method. For example: select user.name,user.age,role.* from.

May.11,2022

pseudo code.

Message::with(['User'=>function($query){
    return $query->select( );//where
}])
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c27d68-338c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c27d68-338c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?