Eloquent tricks

By @lars · 2021-08-30 13:48

Eloquent tricks

  • By @samuel · 2021-08-31 18:31

    The heredocs are a good practice, combining code from multiple languages using normal strings is almost always less readable than that. I try to use heredocs for anything multi-line

    • By @lars · 2021-08-31 19:02

      I should probably do it more often too, I usually stick with just using them for SQL 😬

      • By @samuel · 2021-08-31 19:29

        In Lean I have one field which has a template in the PHP class — it works well for HTML too. VSCode recognizes the language, so all of the plugins like Tailwind CSS Intellisense work there.

        protected function badgeTemplate(): Closure
        {
            return fn (self $field) => <<<HTML
                <span class="
                    inline-flex justify-center items-center px-3 py-0.5 text-sm font-almost-bold rounded-full
                    bg-{$field->color()}-100 text-{$field->color()}-800 dark:bg-{$field->color()}-900 dark:text-{$field->color()}-50
                ">
                    {$field->displayText()}
                </span>
            HTML;
        }