Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrdavidson's avatar

Yajra Datatables

I'm using the following package to better display a rendered table of users for my project. The problem is what I would like to do is extract the logic inside of the ajax check to a new Datatable class that extends the package's default Datatable class. The methods that I'm looking at for the class doesn't exactly line up with what I'm doing.

https://github.com/yajra/laravel-datatables

https://yajrabox.com/docs/laravel-datatables/master/editor-tutorial

public function index(IndexUserRequest $request, DataTables $table, UserFilters $requestFilter)
    {
        $this->authorize('viewList', User::class);

        if ($request->ajax()) {
            $query = User::with('employment');
            $requestFilter->apply($query);

            return $table->eloquent($query)
                ->addColumn('action', 'users.partials.action-cell')
                ->filterColumn('id', function ($query, $keyword) {
                    $query->where($query->qualifyColumn('id'), $keyword);
                })
                ->toJson();
        }

        return view('users.index');
    }
0 likes
0 replies

Please or to participate in this conversation.