laravel-admin icon indicating copy to clipboard operation
laravel-admin copied to clipboard

Fix related column name in the fill method

Open NikolayMurha opened this issue 1 year ago • 0 comments

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.

NikolayMurha avatar Aug 31 '22 08:08 NikolayMurha