Laravel 4.2のEloquentに少し問題があります。まずはテーブルの名前をつけて申し訳ありません。Laravel 4.2 Eloquent belongsToMany 3つのテーブルにマッピング可能な可能性があります
3つのテーブルがあります。
- ユーザーが-Id -Identification -Name -Username ...
- SecurityAreas -Id -Identification -Description ...
- SecurityAccessRights -Id -Identification .. 。 01: は、これらのテーブルは、マッピングテーブルを持っている
を「読み取り」と「書き込み」ちょうど2つのデータセットが含まれています
- SecurityMapping -Id -SecurityAccessAreasId -SecurityAccessRightsId -UsersId
今私は、特定の "エリア" を持つすべてのユーザーと属する "て、AccessRights" を表示しようとしています。したがって、私はこのようなモデルを指定しました:
User.php
class User extends Eloquent implements UserInterace, RemindableInterface {
use UserTrait, RemindableTrait;
protected $table = 'Users';
protected $primaryKey = 'Id';
public $timestamps = false;
protected $hidden = array('password', 'remember_token');
public function securityAreas() {
return $this->belongsToMany('SecurityAreas', 'SecurityMappings', 'UsersId', 'SecurityAreasId');
}
public function securityAccessRights() {
return $this->belongsToMany('SecurityAccessRights', 'SecurityMappings', 'UsersId', 'SecurityAccessRightsId' , 'SecurityAreasId');
}
}
そして私のUserController.phpでは、私はUserを取得しようとしています。
$oUsers = User::with('securityAreas')->with('securityAccessRights')->get();
今雄弁負荷ユーザオブジェクト上のすべての情報...私の見解では、私は、ユーザー名に地域や所属する権利を表示したいです。 "Area"と "AccessRights"の間に所属するのは同じAreaを2回取得するためですが、集められた権限を持つ各ユーザーごとに1回だけ表示したいと考えています。 例: 私の質問は、「AccessRights」に属する所属する固有の領域で「ユーザー」を選択する方法です。コントローラーで結果をソートする機能や可能性はありますか?または私のUsermodelに間違ったことがありますか?可能な限り制限することはできますか?
私は少し混乱していますが...
どのような援助を感謝しています。