Skip to content

Update Column.php: Rename data method to setData #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

bishwajitcadhikary
Copy link

@bishwajitcadhikary bishwajitcadhikary commented Nov 28, 2024

This change renames the data method in the Yajra\DataTables\Html\Column class to setData to resolve a method signature conflict with the parent class Illuminate\Support\Fluent.

public function data(array|string $value): static

This conflicts with the data method in the parent Illuminate\Support\Fluent class, which has the signature:

protected function data($key = null, $default = null)

This results in the following PHP error:

Declaration of Yajra\DataTables\Html\Column::data(array|string $value): static must be compatible with Illuminate\Support\Fluent::data($key = null, $default = null)

Proposed Solution
The data method in the Column class has been renamed to setData to avoid the conflict:

/**
 * Set column data option value.
 *
 * @param  array|string  $value
 * @return $this
 *
 * @see https://datatables.net/reference/option/columns.data
 * @see https://datatables.net/manual/data/orthogonal-data
 */
public function setData(array|string $value): static
{
    $this->attributes['data'] = $value;

    return $this;
}

Benefits of the Fix
1. Conflict Resolution: Avoids the signature conflict with Illuminate\Support\Fluent.
2. Clarity: Improves method naming by explicitly reflecting its purpose (setData for setting values).
3. Backward Compatibility: Allows the Column class to coexist with Fluent without breaking functionality.

Additional Notes
• Any existing usage of data() to set column data will need to be updated to setData() in the codebase.
• This change only affects the method used to set column data. The method inherited from Fluent (data($key = null, $default = null)) remains intact for retrieving data.

Renamed the data method to setData in the Yajra\DataTables\Html\Column class to avoid conflicts with the data method in Illuminate\Support\Fluent
Copy link

@yajra
Copy link
Owner

yajra commented Nov 29, 2024

fixed via #230, thanks!

@yajra yajra closed this Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants