LARAVEL 7刀片组件公共方法不起作用 [英] laravel 7 blade component public methods not working

查看:57
本文介绍了LARAVEL 7刀片组件公共方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Laravel项目在使用blade component时遇到问题。

当我定义新组件并希望使用";组件公共方法&向";查看组件刀片文件";传递数据时,我收到一个错误,&q;未定义变量&q;

该组件的制造者

php artisan make:component testc 

我试了

cache:clear

view:clear

composer dump之前

,编码如下:

组件编码

<?php

namespace AppViewComponents;

use IlluminateViewComponent;

class testc extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return IlluminateViewView|string
     */
    public function render()
    {
        return view('components.testc');
    }

    public function test()
    {
        return 'test';
    }
}

查看组件刀片文件

<div>
    {{ $test }}
</div>

和我的错误

ps:laravel版本为:7.18.0

推荐答案

  • 在刀片文件中,您应该这样调用组件的方法:
<div>
   {{ $test() }}
</div>
  • 注意方括号。

这篇关于LARAVEL 7刀片组件公共方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆