mercredi 19 février 2020

How can I pass a variable to a directive when extending Laravel Blade?

When creating a custom Laravel Blade directive how can I pass a variable in? At the moment the variable passed to the @svg() directive is not parsed and is treated as a string:

Blade view:

@svg($svg->url, 'fill-white')

AppServiceProvider.php

    Blade::directive('svg', function ($arguments) {

        // Funky madness to accept multiple arguments into the directive
        list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
        $path = trim($path, "' ");
        $class = trim($class, "' ");


            dd($path); // Outputs $svg->url

           // Required output = path/to/filename.svg

        });


via Chebli Mohamed

1 commentaire:

  1. This is how my friend Wesley Virgin's adventure starts with this SHOCKING AND CONTROVERSIAL video.

    Wesley was in the military-and shortly after leaving-he revealed hidden, "MIND CONTROL" tactics that the government and others used to get everything they want.

    As it turns out, these are the same secrets lots of celebrities (especially those who "became famous out of nowhere") and top business people used to become rich and famous.

    You probably know that you only use 10% of your brain.

    That's really because the majority of your BRAINPOWER is UNTAPPED.

    Maybe that thought has even taken place IN YOUR very own brain... as it did in my good friend Wesley Virgin's brain around 7 years back, while riding an unregistered, beat-up bucket of a car with a suspended license and with $3.20 in his pocket.

    "I'm absolutely fed up with going through life paycheck to paycheck! When will I finally make it?"

    You've taken part in those types of questions, right?

    Your success story is going to be written. You just have to take a leap of faith in YOURSELF.

    WATCH WESLEY SPEAK NOW

    RépondreSupprimer