master

laravel/framework

Last updated at: 29/12/2023 09:26

CompilesJs.php

TLDR

This file contains a trait named CompilesJs that has a single method named compileJs. The compileJs method compiles the @js directive into valid PHP code.

Methods

compileJs

This method takes a string parameter named $expression and returns a string. It compiles the @js directive into valid PHP code by using the Js class from the Illuminate\Support namespace.

Classes

No classes found.

<?php

namespace Illuminate\View\Compilers\Concerns;

use Illuminate\Support\Js;

trait CompilesJs
{
    /**
     * Compile the "@js" directive into valid PHP.
     *
     * @param  string  $expression
     * @return string
     */
    protected function compileJs(string $expression)
    {
        return sprintf(
            "<?php echo \%s::from(%s)->toHtml() ?>",
            Js::class, $this->stripParentheses($expression)
        );
    }
}