I just started to learn the association model of laravel, and I was so confused that sometimes I really felt that it was not as convenient as writing sql directly.
now there is a problem
role tables admin_roles and admin_permissions tables have a many-to-many relationship.
the intermediate table admin_role_permissions has only two fields
role_id and permission_id. Corresponds to the id of the admin_roles and admin_permissions tables, respectively.
now I want to check the id value of admin_permissions table when id is 1 and 2 in admin_roles table. You can write
in sql.SELECT
DISTINCT`admin_role_permissions`.permission_id
FROM
`admin_permissions`
INNER JOIN `admin_role_permissions` ON `admin_permissions`.`id` = `admin_role_permissions`.`permission_id`
WHERE
`admin_role_permissions`.`role_id` IN (1, 2)
data obtained
laravel ,
AdminRoleController.php
AdminRole.php
the data is so complex, there are too many levels, and it hasn"t been deduplicated yet. How can we get the data results executed by the top sql? I don"t want to write the native sql
how to find the Permissions=. The value in this form is
how to rewrite it with the model, or how to get it with the collection.