z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

Fix related column name in the fill method #5646

Closed NikolayMurha closed 2 years ago

NikolayMurha commented 2 years ago

Hello.

I found problem with hasOne relation with snakeCased method.

For example, when I have class like this:

class CartItem {
    public function productVariant() {
        return $this->belongsTo(ProductVariant::class);
    }
}

And grid like this

$cartItemsGrid->column('productVariant', 'Product Variant')->display(function ($row) {
    return $row;
});

I have an empty row because the loaded field has the name product_variant but column name like relation method - productVariant.

When I used product_variant for relation, related data didn't load, because the relation method name does not matched:

$cartItemsGrid->column('product_variant', 'Product Variant')->display(function ($row) {
    return $row;
});

My solution in this PR.