This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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?
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
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 ;
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
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
hi @daftspunk
How to convert the datetime column into date and groupby with the listExtendQuery() function?
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