Easyadminbundle: [Help][3.x.x] Filter entity fields by custom field

Created on 18 Jul 2020  路  2Comments  路  Source: EasyCorp/EasyAdminBundle

I need help please
I've had a problem for a few days now.

I have an EasyAdmin with many users, but each user should only be able to create or edit their own data records.

Creating a record for a user is not a problem. But the display only of the user record in INDEX so that he can only edit his records

As an an example:
A user can have many hostels with many room_types.
If the user now displays the Crud :: INDEX page of room_types. Should he only be shown room_types with his hostel_id.
I despair of that
hostel

All 2 comments

You can override the createIndexQueryBuilder function in your crud controller so that it only shows the records he's entitled to

Thank you for your answer.
I always thought of this function. But I have always focused too much on what comes into the function for objects. Instead of thinking about what is supposed to get out

it works thanks

 public function createIndexQueryBuilder(
        SearchDto $searchDto,
        EntityDto $entityDto,
        FieldCollection $fields,
        FilterCollection $filters
    ): QueryBuilder {

        $test = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
        $alias = $test->getRootAliases();
        $test->andWhere($alias[0].'.user_id = 4');
        return $test;
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ndench picture ndench  路  4Comments

bocharsky-bw picture bocharsky-bw  路  3Comments

joazvsoares picture joazvsoares  路  4Comments

devkbsc picture devkbsc  路  3Comments

ghost picture ghost  路  3Comments