MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 259 forks source link

error SQLSTATE[42S22] - 1054 with export #484

Open Slobug opened 1 year ago

Slobug commented 1 year ago

Hi

when I export some datatable I have this message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column

The column is a relation like : post.name

My config

        "php": "^7.3|^8.0", ->php 7.4  
        "bonecms/laravel-captcha": "^2.2",  
        "fideloper/proxy": "^4.4",  
        "fruitcake/laravel-cors": "^2.0",  
        "guzzlehttp/guzzle": "^6.5",  
        "intervention/image": "^2.7",  
        "laravel-frontend-presets/tall": "^3.1",  
        "laravel-lang/lang": "~8.0",  
        "laravel/fortify": "^1.7",  
        "laravel/framework": "^8.12",  
        "laravel/horizon": "^5.9",  
        "laravel/tinker": "^2.5",  
        "livewire-ui/modal": "^1.0",  
        "livewire/livewire": "^2.4",  
        "mediconesystems/livewire-datatables": "^0.7.0",  
        "phpsa/laravel-yourls-plugin": "^1.2"  

someone to help me ? ;)

arlanram commented 1 year ago

the same issue. please @marksalmon look at this

arlanram commented 1 year ago

@marksalmon @thyseus @tomshaw @trippo please help

when exporting datatable, there is error "Unknown column", and no JOINS in query

mansiprajapati commented 1 year ago

the same issue. please @marksalmon look at this

tomshaw commented 1 year ago

@Slobug @arlanram @mansiprajapati I need to narrow down the issue. There's no way I can reproduce the error without more detail. I haven't looked at the library in a while so I downloaded the latest Laravel/Jetstream Livewire. Factoried a few hundred users. Cloned the latest livewire-data tables and created a user grid. I was unable recreate any errors.

mansiprajapati commented 1 year ago

@tomshaw Try to add a relation column in the data table and export the data this way you can regenerate this error

tomshaw commented 1 year ago

@mansiprajapati Can I see your column type.

nathcast commented 1 year ago

I have found out that export didn't work for me for same reasons as long as I was using public $model, but when I used the query builder, it worked. Does that help?

Slobug commented 8 months ago

I have found out that export didn't work for me for same reasons as long as I was using public $model, but when I used the query builder, it worked. Does that help?

I @nathcast ,

Thank you very much for your help. I had to put my problem on hold but thanks to you and a little digging through the code in the vendor folder, I was able to solve my problem.

If it helps anyone, if you want a custom export :
add : use Illuminate\Support\Facades\DB;

public $exportable = false; public $customexportable = true;

with this, the "export" button will return to a custom function "customexport".

` public function customexport() {

    $data = DB::table('table1')
    ->select(
        'table1.column', 
        'table1.columNameLikeTable2 AS otherName_a', 
        'table2.discipline', 
        'table2.columNameLikeTable1 AS otherName_b',
        )
    ->leftJoin('table2', 'table2.id', '=', 'table1.user_id')
    ->get();

    $export = new DatatableExport($data);

    return $export->download();
}`