Forum

error laravel 5 undefined variable

controller public function index() { $meetingData = Newsnotice::news(); $meetingData=json_decode(json_encode($meetingData),true); return view('index',$meetingData); }

in view file index.blade.php echo'<pre>'; print_r($meetingData);

error Undefined variable: meetingData (View: C:\xampp\htdocs\lara_wcd_pension\resources\views\index.blade.php)

rahulemaity
rahulemaity
  • 1 month ago

use return view('index',array(meetingData"=>$meetingData)); OR return view('index',compact($meetingData));

Try:

public function index() 
{ 
    $meetingData = Newsnotice::news(); 
    $meetingData = json_decode(json_encode($meetingData),true); 
    return view('index', compact('meetingData'));
}