hendraspt hendraspt - 1 year ago 67
PHP Question

How to solve the "Undefined variable" error in laravel?

I am using laravel, and I have got an error:

Undefined variable: getFormTest (View: C:\xampp\htdocs\survey\resources\views\tambahformtest.blade.php)

That error references to this view :

<input value="{{ $getFormTest[0]->ms_test }}">

I have put
in my controller.

public function TambahFormTest()
$ms_id = FormTest::max('ms_id');
$getFormTest = FormTest::Select('ms_test')->where('ms_id', '=', $ms_id)->get();

return view('tambahformtest', $getFormTest);

Answer Source

When returning a view in laravel, you have to pass an array of params.

return view ('myView', ['param1' => $v1, 'param2', $v2]);

then in your view

   {{ $params->property }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download