Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

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

Working fine in local machine but not working in live server.

check below code I pass data to view.

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

below is local machine screen shot , which is working fine.

enter image description here

News blade code:

<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>

View Component class

<?php

namespace AppViewComponents;
use AppModelscampusevent;
use IlluminateViewComponent;

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 IlluminateContractsViewView|Closure|string
     */
    public function render()
    {  
        $datanews=campusevent::where('Type',"=" ,'1')->orderBy('id', 'DESC')->limit(4)->get();

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

DD Use

dd($datanews->toArray());

enter image description here

Database table and data exist

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Rename component class name , so that it must start with uppercase letter.

class News extends Component{
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...