LaravelRUS / SleepingOwlAdmin

🦉 Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
805 stars 217 forks source link

AdminColumnFilter::select() not working as expected #725

Closed AlexGrati closed 7 years ago

AlexGrati commented 7 years ago

en

Version in Composer.json

"laravelrus/sleepingowl": "4.*dev",

Steps to reproduce

So this is the code of the model that i am registering for the AdminSection

`AdminSection::registerModel(\App\TipoVeicolo::class, function ($model) {
    $model->setTitle('Tipi di Veicoli');
    //$model->enableAccessCheck();
    $model->setAlias('veicoli'); 
// Display
    $model->onDisplay(function () {
        $display = AdminDisplay::datatables()->setHtmlAttribute('class', 'table-primary');
        $display->with('parcheggio');
        $display->setFilters(
            AdminDisplayFilter::related('parcheggio_id')->setModel(\App\Parcheggio::class)
        );
    $display->setColumns([
        AdminColumn::text('nome')->setLabel('Nome'),
        AdminColumn::text('prezzo')->setLabel('Prezzo'),
        AdminColumn::text('posti')->setLabel('Posti'),
        AdminColumn::text('utilizzati')->setLabel('Posti Acquistati'),
        AdminColumn::text('parcheggio.nome')->setLabel('Parcheggio')
            ->append(AdminColumn::filter('parcheggio_id')),
    ]);
/**Problem here**/
        $display->setColumnFilters(
            null,
            null,
            null,
            null,
            AdminColumnFilter::select(\App\Parcheggio::class, 'id')
                ->setDisplay('nome')
               /*Query used to display select options based on different users
                  even if removed search still doesn't work*/
                ->setLoadOptionsQueryPreparer(
                    function($element, $query) {
                        $azienda = auth()->user()->azienda_id;
                        $query->where('azienda_id', $azienda);
                        return $query;
                    })
                ->multiple(),
        ]);
    //$display->getColumnFilters()->setPlacement('table.header');

    $display->paginate(15);
    $display->setApply(function ($query) {
        if (auth()->user()->getRole() == 'azienda') {
            $query->whereIn('parcheggio_id',function ($subquery){
                $azienda = auth()->user()->azienda_id;
                $subquery->select('id')->from('parcheggio')->where('azienda_id',$azienda);
            });
        }
        $query->orderBy('nome', 'asc');
    });
    return $display;
});

`

What is expected?

1.The admin AdminColumnFilter::select() should filter the data based on the selected option

What is actually happening?

1.The filter doesn't work and shows 'No matching records found.' so i was wondering if i was doing something wrong or it is a bug


ghost commented 7 years ago

@AlexGrati So you use some of old variant to use sections. Connect us in telegram http://t.me/sleeping_owl. We can answer on that question