I am trying to create a relationship between permission
and item_permission
. The problem is that I need to check if the two columns on each table match, permission.op_id = item_permission.op_id
and permission.screen_id = item_permission.screen_id
.
class Permission extends Model
{
public function itemPermission()
{
// This should also match the screen_id column in each table.
return $this->hasMany('App\ItemPermission', 'op_id', 'op_id');
}
}
Using SQL is easy; I use "and" in the inner join between permission and item_permission. But with Eloquent, I cannot achieve it. I've tried all day to solve this problem but I couldn't. I want to be able to use a query like the following.
$permission->with('itemPermission)->get()