InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 812 forks source link

Cannot access "appends" properties in datatables #537

Closed dhcmega closed 5 years ago

dhcmega commented 6 years ago

Hi At first, with "old" way of generating the ModelDataTable.php file, if the model has this:

    protected $appends = [
        'full_name',
    ];

    public function getFullNameAttribute()
    {
        return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
    }

    $guests->with('event.user')->select('guests.*');

this would work:

            'user' => ['name' => 'event.user.full_name', 'data' => 'event.user.full_name',

But now, since a couple of month ago, with the new version of the generator, the DataTable file is very different and the $appends attribute is ignored.

Can any one tell me how to make it work again?

Thanks!

ajayinfyom commented 5 years ago

@dhcmega Once read this blog https://blog.infyom.com/how-to-display-relationship-data-into-yajra-datatables-with-infyom-laravel-generator

$appends attribute working fine in the new version of the generator as well

Your Solution: On query() function need to return query like this $model->newQuery()->with(['event.user']);

and need to add this one while getting datatable columns in getColumns() function 'user' => ['name' => 'event.user.full_name', 'data' => 'event.user.full_name']