<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                > ## 多對多關聯:描述:如用戶和角色的關系 > ### belongsToMany('關聯模型名','中間表名','外鍵名','當前模型關聯鍵名',['模型別名定義']); ### 關聯定義 ``` class User extends Model { public function roles() { return $this->belongsToMany('Role'); // 設置中間表 return $this->belongsToMany('Role','\app\index\model\Access'); } } class Role extends Model { public function users() { return $this->belongsToMany('User'); } } ``` ### 關聯查詢 ``` // 獲取一個用戶的所有角色 $user = User::get(1); dump($user->roles); // 獲取中間表數據 $user = User::get(1); $roles = $user->roles; foreach($roles as $role){ dump($role->pivot); } ``` ### 關聯新增 ``` $user = User::get(1); // 給某個用戶新加一個管理員的角色 $user->roles()->save(['name'=>'管理員']); // 批量增加關聯數據 $user->roles()->saveAll([ ['name'=>'管理員'], ['name'=>'操作員'], ]); $user = User::get(1); // 僅增加關聯的中間表數據 $user->roles()->save(1); // 或者 $role = Role::get(1); $user->roles()->save($role); // 批量增加關聯數據 $user->roles()->saveAll([1,2,3]); // 單獨更新中間表 $user = User::get(1); // 增加關聯的中間表數據 $user->roles()->attach(1); // 傳入中間表的額外屬性 $user->roles()->attach(1,['remark'=>'test']); // 刪除中間表數據 $user->roles()->detach([1,2,3]); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看