This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

development7672
development7672

Hello,

I am trying to add

public function listExtendQuery($query)
{
    $query->whereNull('department_id');
    $query->whereNull('organization_id');
}

To the Users.php controller, so I can filter out people who are part of departments/organizations (a newly added field) but I am unable to figure out how best to do this. I've tried using all the end methods I can find and stuff. Any thoughts on how I can add two where statements to the list query?

Scott
Scott

You need to also add an index method to extend the query

public function index($userId = null)
{
    $this->asExtension('ListController')->index();
}

public function listExtendQuery($query)
{
    $query->whereNull('department_id')->whereNull('organization_id');
}

Last updated

development7672
development7672

Where do I put this index method and listExtendQuery?

daftspunky
daftspunky

I don't think you need to define an index() method, the listExtendQuery() method should work regardless.

It should be defined in your back-end controller.

development7672
development7672

Yes, but I want to add this function to Users.php (RainLab.User) plugin.

planetadeleste
planetadeleste

@development7672 ;

Do you find how to override listExtendQuery() from boot() ?

I try using Event::listen with filter.extendQuery and backend.filter.extendQuery but I can't make it work...

Thanks

planetadeleste
planetadeleste

I figured how to do it. Don't know if is the correct way, but works.

http://octobercms.com/forum/post/extend-list-filters?page=1#post-10499

sushma30159
sushma30159

hi @daftspunk

How to convert the datetime column into date and groupby with the listExtendQuery() function?

candrabeqx
candrabeqx

I think this is the best solution for now:

\Event::listen('backend.list.extendQuery', function ($listWidget, $query) {
    if (get_class($listWidget->getController()) !== 'Backend\Controllers\Users')
        return;
    $query->whereNull('department_id');
    $query->whereNull('organization_id');
});

add to your boot() method on Plugin.php.

Last updated

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.