filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.1k stars 2.83k forks source link

The `Undefined variable $listLimit` error is produced when `default()` and `listWithLineBreaks()` column methods are used together. #10314

Closed kidereo closed 9 months ago

kidereo commented 9 months ago

Package

filament/filament

Package Version

v3.1.21

Laravel Version

v10.37.3

Livewire Version

v3.3.0

PHP Version

v8.2.11

Problem description

The default() and listWithLineBreaks() column methods no longer work together. They do work individually but produce Undefined variable $listLimit error when both are used on the same column. They did work together prior to v3.1 update.

Expected behavior

A column on which listWithLineBreaks() is used is expected to show the value of the default() method if its state is empty.

Steps to reproduce

Clone reproduction repository. Run migrations with seeder. Navigate to Books resource. Observe some books having authors on one line and some books having dashes (no authors). In the BookResource, uncomment listWithLineBreaks() and comment default('-'). Observe some books having authors on multiple line and some books having nothing in the Authors column. In the BookResource, uncomment default('-'). Observe Undefined variable $listLimit error.

Reproduction repository

https://github.com/kidereo/filamentphp-issues

Relevant log output

No response

danharrin commented 9 months ago

default() sets the default state of the column when there is no other content. Filament treats it as if it was real content. In this case, you're passing a string to default() instead of an array, and since Filament treats it as real content, it breaks listWithLineBreaks() since that expects an array.

placeholder() is different, and allows you to pass in a string that is shown when there is no other content. It does not need to abide by the data type rules of the real content.

So either use placeholder('-'), or default(['-']). The placeholder will be slightly lighter in color, whereas the default will look like actual content.

The fact this worked previously was a bug as default() array content was not being output as it should have been. In the next release, I've fixed the exception so you can still use both methods together, but you shouldn't.

kidereo commented 9 months ago

Perfect explanation, and indeed default(['-']) works perfectly. Many thanks for taking time to explain and for the Filament package in general!