zofe / rapyd-laravel

deprecated rewritten in rapyd-livewire
MIT License
866 stars 297 forks source link

Is it possible to get filtered data in controller? #439

Closed seriousTom closed 6 years ago

seriousTom commented 6 years ago

Hi, I want to use rapyd data filter, but at first I need to proccess filtered data in my controller before passing it to view. My code: `public function index() { $user = auth()->user();

    $filter = \DataFilter::source(Task::with('project')->whereHas('project', function ($q) use ($user) {
        $q->where('user_group', $user->user_group_id);
    }));
    $filter->add('task_id', trans('ID'), 'text');
    $filter->add('name', trans('Name'), 'text');
    $filter->add('project_id', trans('Project ID'), 'select')->option('', trans('All projects'))->options(Project::orderBy('name', 'asc')->pluck('name', 'id'));
    $filter->submit('search');
    $filter->reset('reset');

    $tasks = $filter->query->get();

}`

But in controller this line $tasks = $filter->query->get(); doesnt return filtered data. It returns all data. I noticed that it works only when the filter view is rendered. So is it possible to achieve it in controller?

seriousTom commented 6 years ago

Nevermind. I was missing $filter->build()

zofe commented 6 years ago

k