Emile Pels February 2016

Eloquent IF clause - always returns true

I am using Entrust's default table structure:

permissions table:

+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| id           | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name         | varchar(255)     | NO   | UNI | NULL    |                |
| display_name | varchar(255)     | YES  |     | NULL    |                |
| description  | varchar(255)     | YES  |     | NULL    |                |
| created_at   | timestamp        | NO   |     | NULL    |                |
| updated_at   | timestamp        | NO   |     | NULL    |                |
+--------------+------------------+------+-----+---------+----------------+

permission_role table:

+---------------+------------------+------+-----+---------+-------+
| Field         | Type             | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+-------+
| permission_id | int(10) unsigned | NO   | PRI | NULL    |       |
| role_id       | int(10) unsigned | NO   | PRI | NULL    |       |
+---------------+------------------+------+-----+---------+-------+

roles table:

+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| id           | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name         | varchar(255)     | NO   | UNI | NULL    |                |
| display_name | varchar(255)     | YES  |     | NULL    |                |
| description  | varchar(255)     | YES  |     | NULL    |                |
| created_at   | timestamp        | NO   |     | NULL    |                |
| updated_at   | timestamp          

Answers


lesssugar February 2016

Structurally, the Query Builder query you've shown looks fine.

What does not look fine is the left join. Shouldn't this:

->leftJoin('permission_role', 'permission_role.permission_id', '=', 'permission_role.role_id')

be this:

->leftJoin('permission_role', 'permission_role.permission_id', '=', 'permissions.id')

?

Post Status

Asked in February 2016
Viewed 2,132 times
Voted 5
Answered 1 times

Search




Leave an answer