lara-zeus / bolt

form builder for your users, with so many use cases
https://larazeus.com/bolt
MIT License
172 stars 31 forks source link

fix for is pro not installed #295

Closed atmonshi closed 3 months ago

what-the-diff[bot] commented 3 months ago

PR Summary

eelco2k commented 3 months ago

I see now if not pro: an empty array item. But why not the array_filter() ? As it completely removes that item from the list. .. thank you for fast fix 👌🏻

atmonshi commented 3 months ago

🤔 can you explain how to use it with conditional array item?

...Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::schema($field) : [],

eelco2k commented 3 months ago

well i only meant it for this function:

public static function getOptionsHidden(): array
    {
        return [
            // @phpstan-ignore-next-line
            Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::hidden() : null,
            self::hiddenDataSource(),
            self::hiddenVisibility(),
            self::hiddenHtmlID(),
            self::hiddenHintOptions(),
            self::hiddenRequired(),
            self::hiddenColumnSpanFull(),
        ];
    }

wrap the array with array_filter() function like so:

public static function getOptionsHidden(): array
    {
        return array_filter([
            // @phpstan-ignore-next-line
            Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::hidden() : null,
            self::hiddenDataSource(),
            self::hiddenVisibility(),
            self::hiddenHtmlID(),
            self::hiddenHintOptions(),
            self::hiddenRequired(),
            self::hiddenColumnSpanFull(),
        ]);
    }

it will completely remove the null / empty array items, so you don't have an empty array item in the array which you return. Keeps the return array of getOptionsHidden() clean.

atmonshi commented 3 months ago

you're right, but instead of duplicate the array_filter on all classes I am already cleaning it up when been called here :)

eelco2k commented 3 months ago

Ah didn't see that one in the commits. you already found a way. that's perfect!