66use Rappasoft \LaravelLivewireTables \Views \Columns \Traits \Configuration \ArrayColumnConfiguration ;
77use Rappasoft \LaravelLivewireTables \Views \Columns \Traits \Helpers \ArrayColumnHelpers ;
88use Rappasoft \LaravelLivewireTables \Views \Columns \Traits \IsColumn ;
9+ use Illuminate \Database \Eloquent \Model ;
10+ use Illuminate \Support \HtmlString ;
11+ use Rappasoft \LaravelLivewireTables \Exceptions \DataTableConfigurationException ;
912
1013class ArrayColumn extends Column
1114{
@@ -32,4 +35,31 @@ public function __construct(string $title, ?string $from = null)
3235 $ this ->label (fn () => null );
3336 }
3437 }
38+
39+
40+ public function getContents (Model $ row ): null |string |\BackedEnum |HtmlString |DataTableConfigurationException |\Illuminate \Contracts \Foundation \Application |\Illuminate \Contracts \View \Factory |\Illuminate \Contracts \View \View
41+ {
42+ $ outputValues = [];
43+ $ value = $ this ->getValue ($ row );
44+
45+ if (! $ this ->hasDataCallback ()) {
46+ throw new DataTableConfigurationException ('You must set a data() method on an ArrayColumn ' );
47+ }
48+
49+ if (! $ this ->hasOutputFormatCallback ()) {
50+ throw new DataTableConfigurationException ('You must set an outputFormat() method on an ArrayColumn ' );
51+ }
52+
53+ foreach (call_user_func ($ this ->getDataCallback (), $ value , $ row ) as $ i => $ v ) {
54+ $ outputValues [] = call_user_func ($ this ->getOutputFormatCallback (), $ i , $ v );
55+ }
56+
57+ $ returnedValue = (! empty ($ outputValues ) ? implode ($ this ->getSeparator (), $ outputValues ) : $ this ->getEmptyValue ());
58+
59+ if ($ this ->hasOutputWrapperStart () && $ this ->hasOutputWrapperEnd ()) {
60+ $ returnedValue = $ this ->getOutputWrapperStart ().$ returnedValue .$ this ->getOutputWrapperEnd ();
61+ }
62+
63+ return new HtmlString ($ returnedValue );
64+ }
3565}
0 commit comments