i have 3 tables: role,threadpermission, , thread. table structure follows:
role - id - name threadpermission - id - role_id - thread_id - is_moderator (bool) thread - id - title here's screenshot of threadpermission data:
i having hard time explaining relationship (that's why edits)
so, when create new thread object, create new threadpermission object assign is_moderator attribute each role, can see in screenshot above
i wish access thread via role method is_moderator equals true in threadpermission. there's 2 problem seems need solve, first building relationship between role thread, second 1 show thread @ is_moderator == true in threadpermission
to handle first problem tried implementing in role class:
class role extends eloquent { public function moderatedthreads() { // can 'threadpermission'->where('is_moderator', true) return $this->hasmanythrough('thread', 'threadpermission', 'role_id', 'id')->get(); } } but when try var_dump method:
var_dump($app->user->roles()->moderatedthreads()); it returns empty object
object(illuminate\database\eloquent\collection)#203 (1) { ["items":protected]=> array(0) { } } i confused part of implementation did mess up. guys can see can't see?

Comments
Post a Comment