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

RomaldyMinaya
RomaldyMinaya

Hi,

In a tutorial made by the octoberCms team you can achieve this:

$config = $this->makeConfig('$/acme/formist/models/customer/columns.yaml');

$config->model = new \Acme\Formist\Models\Customer;

$config->recordUrl = 'acme/formist/mycontroller/update/:id';

$widget = $this->makeWidget('Backend\Widgets\Lists', $config);

$widget->bindToController();

$this->vars['widget'] = $widget;

I'd like to know how I can pass to a list a custom query like this instead:

$config = $this->makeConfig('$/acme/formist/models/customer/columns.yaml');

//$config->model = new \Acme\Formist\Models\Customer;
$config->query = DB::table('users')
    ->join('contacts', 'users.id', '=', 'contacts.user_id')
    ->join('orders', 'users.id', '=', 'orders.user_id')
    ->select('users.*', 'contacts.phone', 'orders.price');
$config->recordUrl = 'acme/formist/mycontroller/update/:id';

$widget = $this->makeWidget('Backend\Widgets\Lists', $config);

$widget->bindToController();

$this->vars['widget'] = $widget;

This way I can create my own reports based on custom queries. Thanks

alxy
alxy

There are a few events that you might want to use: https://github.com/octobercms/october/blob/master/modules/backend/widgets/Lists.php#L336

I recommend to checkout the sources to dig deeper into advanced topics.

mihau
mihau

It is very very bad answer! Could you give some more obvious solution? if you know how to achive this please just answer.

PennyLliang
PennyLliang

Hi all, here is what I've done:

$config = $this->makeConfig('$/acme/formist/models/customer/columns.yaml');
$config->recordUrl = 'acme/formist/mycontroller/update/:id';
$widget = $this->makeWidget('Backend\Widgets\Lists', $config);
$widget->bindEvent('list.extendQueryBefore', function ($query) {
    return $this->searchQuery($query);
});
$widget->bindToController();
$this->vars['widget'] = $widget;

then, create another function to do query:

public function searchQuery($query)
{
  // Do some query here!
}

Last updated

1-4 of 4

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