Problems associated with laravel model

user table and role table have many-to-many relationship, and the middle table is user_roles.

many-to-many relationships are defined in the user model class

    public function relRole(){
        return $this->belongsToMany("App\Model\Role","user_roles","user_id","role_id");
    }

get the id of role with user 2 in the userController controller class, my code

$data=AdminUser::with("relRole")->where("id",2)->get()->toArray();

the problem now: getting a lot of data, and I only want the relevant id values in the role table, how to write it, only using the model method, regardless of query constructor and native.

clipboard.png

Apr.01,2022

$data=AdminUser::with('relRole:id')->where('id',2)->get()->toArray();

  https://laravelacademy.org/po... many to many parts 

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-1bef7af-31c9d.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-1bef7af-31c9d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?