Laravel replace QueryDataTable.php from yajra datatable

413 Views Asked by At

I need to replace the function compileQuerySearch() from the yajra datatable vendor but I can't seems to get it right ...

This is the original function

<?php

namespace Yajra\DataTables;

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;
use Yajra\DataTables\Utilities\Helper;

class QueryDataTable extends DataTableAbstract
{
    // [...]
    protected function compileQuerySearch($query, $column, $keyword, $boolean = 'or')
    {
        $column = $this->addTablePrefix($query, $column);
        $column = $this->castColumn($column);
        $sql    = $column . ' LIKE ?';

        if ($this->config->isCaseInsensitive()) {
            $sql = 'LOWER(' . $column . ') LIKE ?';
        }

        $query->{$boolean . 'WhereRaw'}($sql, [$this->prepareKeyword($keyword)]);
    }
    // [...]
}

And I need to replace that with this:

<?php

namespace App\Http\yajra; // Changed this line

use Illuminate\Support\Str;
use Illuminate\Database\Query\Builder;
use Yajra\DataTables\Utilities\Helper;
use Yajra\DataTables\DataTableAbstract; // Changed this line
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

class QueryDataTable extends DataTableAbstract
{
    //[...]
    protected function compileQuerySearch($query, $column, $keyword, $boolean = 'or')
    {
        if ($column!="transaction_date" && $column!="settlement_date"){ // Changed this line
            $column = $this->addTablePrefix($query, $column);
            $column = $this->castColumn($column);
            $sql    = $column . ' LIKE ?';

            if ($this->config->isCaseInsensitive()) {
                $sql = 'LOWER(' . $column . ') LIKE ?';
            }

            $query->{$boolean . 'WhereRaw'}($sql, [$this->prepareKeyword($keyword)]);
        } // Changed this line
    }
    //[...]
}

The original file is located at

\vendor\yajra\laravel-datatables-oracle\src\QueryDataTable.php

My file is located at

\app\Http\yajra\QueryDataTable.php

I tried excluding the file from composer and adding it to the psr-4 like this

"autoload": {
    "exclude-from-classmap": ["vendor/yajra/laravel-datatables-oracle/src/QueryDataTable.php"],
    "psr-4": {
        "App\\": "app/",
        "yajra\\": "app/Http/yajra"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},

Then I of course ran composer dump auto-load

But for some reason it always loads the original class discarding my version. To confirm that, I added a dd("Please crash") on top on my class to see if it loads my version and not the original ... unfortunately it does not crash ... so my class is not the one loaded. (First time I actually want something to crash very badly lol)

0

There are 0 best solutions below