This is how you can do it:
User::where('id', $id)->with(['groups.permissions' => function ($q) use (&$permissions) {
$permissions = $q->get()->unique();
}])->first();
// then
$permissions; // collection of unique permissions of the user with id = $id
More Related Contents:
- Laravel one to many relation with a one to one relation
- How to do this in Laravel, subquery where in
- Laravel OrderBy relationship count
- Laravel 5.2 – Use a String as a Custom Primary Key for Eloquent Table becomes 0
- Laravel $q->where() between dates
- Eloquent groupBy make “SQLSTATE[42000]” with valid SQL query in Laravel 5.3
- How do I store a custom user selected CSS template style (like wordpress visual editor)? [closed]
- Laravel – only a zero is saved to the database
- How to use multiple databases in Laravel
- How do I get the query builder to output its raw SQL query as a string?
- Laravel Check If Related Model Exists
- Laravel migration: unique key is too long, even if specified
- Laravel: PDOException: could not find driver
- Laravel Eloquent select all rows with max created_at
- Laravel Model with Two Primary Keys update [duplicate]
- Laravel: connect to databases dynamically
- Laravel eager loading with limit
- How to bind parameters to a raw DB query in Laravel that’s used on a model?
- Laravel Eloquent: How to order results of related models?
- SQLSTATE[HY000] [2002] A connection attempt failed.. – When attempting to connect from Local to remote server
- How to set a default attribute value for a Laravel / Eloquent model?
- Laravel Migration table already exists, but I want to add new not the older
- Laravel – Database, Table and Column Naming Conventions?
- Order By before Group By using Eloquent (Laravel)
- How to Merge Two Eloquent Collections?
- Difference between Eloquent\Model::get() and all()
- Laravel Eloquent get results grouped by days
- Laravel 4.1: How to paginate eloquent eager relationship?
- How to create a database-driven multi-level navigation menu using Laravel
- Laravel Eloquent update just if changes have been made