laravel 查看组件 class 不发送数据到实时服务器中的查看组件

laravel view component class not send data to view component in live server

Undefined variable: datanews (View: /home1/ctgroirh/public_html/maqsudan.ctgroup.in/maqsudan/resources/views/components/news.blade.php)

http://maqsudan.ctgroup.in/open

在本地机器上工作正常但在实时服务器上不工作。

检查下面的代码我将数据传递给视图。

  return view('components.news',["datanews"=>$datanews ]);

下面是本地机器的屏幕截图,工作正常。

新闻blade代码:

<div>
    <!-- Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant -->

 <h2 class="bggridient" style="color:white;padding:10px;text-align:center;">
   News    </h2>
 <?php 
  for ($x = 0; $x < count($datanews); $x++) {
     
    ?>
 data come here
   
    <?php 
  }
    
    ?>

<center> <a href="/All-News" class="btn btn-default"> More News</a> </center>




</div>

查看组件class

<?php

namespace App\View\Components;
use App\Models\campusevent;
use Illuminate\View\Component;

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

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {  
        $datanews=campusevent::where('Type',"=" ,'1')->orderBy('id', 'DESC')->limit(4)->get();

        return view('components.news',["datanews"=>$datanews ]);
    }
}

DD使用

dd($datanews->toArray());

数据库table和数据存在

小写 class 名称在开发中有效但在生产中无效。此错误或错误可能来自 Laravel 框架。

只需将组件的名称class从小写更改为大写

首字母必须大写

喜欢下面->

class news extends Component{
              }

class News extends Component {
        }

并重命名来自 <x-news /> to <x-News />

的组件

及其工作原理

重命名组件 class 名称,使其必须以大写字母开头。

class News extends Component{
}

是的!这有效!问题是 “首字母必须大写”

我不知道为什么,但是在服务器 Laravel 中将组件识别为“匿名组件”,因此在视图中我们没有任何 class.

就我而言,我的名字是: class ComponentOne extends Component

并使用:

<x-Component-one :param1="$miParam" :param2="otherParam"/>