Laravel Livewire内联组件返回语法错误

问题描述 投票:0回答:1

我使用的是Laravel 7

当我使用这个命令创建一个内联组件时。

php artisan livewire:make HelloWorld3 --inline

它返回给我一个语法错误

ErrorException语法错误,文件结尾出乎意料,期待变量(T_VARIABLE)或heredoc结尾(T_END_HEREDOC)或${ (T_DOLLAR_OPEN_CURLY_BRACES)或{$ (T_CURLY_OPEN) (View: varwwwhtmll7livewireresourcesviewswelcome.blade.php)

我的HelloWorld3.php代码在aphttplivewire上。

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class HelloWorld3 extends Component
{
    public function render()
    {
        return <<<'blade'
            <div>
                {{-- Be like water. --}}
            </div>
        blade;
    }
}
laravel heredoc laravel-livewire
1个回答
1
投票

听起来你运行在 PHP 7.2 上--而这个语法要求你运行在 PHP 7.3 上。

PHP 7.3 引入了 灵活的世袭语法 其中可以缩进 heredoc 字符串的结束定界符(即"blade;")--在此之前,结尾定界符根本不能缩进。

修正后的代码块在 PHP 7.2 中的工作原理如下。

class HelloWorld3 extends Component
{
    public function render()
    {
        return <<<'blade'
            <div>
                {{-- Be like water. --}}
            </div>
blade;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.