未定义变量匿名组件laravel 8

问题描述

我是 laravel 的新手,我正在尝试学习如何使用组件,但是当我在另一个组件中使用匿名组件时,我面临“未定义变量”的问题。

我的 indexController 返回一个欢迎视图,在这个视图中我想包含一个来自其他控制器的帖子列表。

索引控制器

class IndexController extends Controller
{
    public function showIndex()
    {
        return View('welcome');
    }
}

欢迎视图(resources/views/welcome.blade.PHP

<x-app-layout title="welcome">
<p>Welcome page</p>

//component I want to include
<x-annonces-list></x-annonces-list>

</x-app-layout>

ListAnnoncesController

class ListAnnonceController extends Controller
{
    public function show()
    {
        $annonces = DB::table('annonces')->get();
        return View('annonces-list',['annonces',$annonces]);

    }
}

我想在欢迎视图中显示的列表 (resources/views/components/annons-list.blade.PHP)

<p>Lorem ipsum dolor sit,amet consectetur adipisicing elit. Odit ipsam autem,nam neque incidunt iure voluptas fugit,quo illo,dicta ducimus maiores. Consequatur molestiae dolore autem SAEpe? Omnis,distinctio maxime.</p>

@foreach ($annonces as $annonce)
    <p>Title: {{$annonce->title}}</p>
@endforeach

组件文件夹和 在我安装“breeze”包时已经创建。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)