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.
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());
Database table and data exist
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…