I've passed a variable temp from controller to view page.
While debugging the search method, I am getting data from database to the variable temp.
When I pass this variable to view page, it is showing error as
ErrorException (E_ERROR)
Undefined variable: temp (View: C:\xampp\htdocs\laravel\lsapp\resources\views\pages\MySearch.blade.php)
I doubt the error is most likely due to route configuration but I am not sure. There might be other errors too. But the process of passing variable from controller to view page is same, but also I am getting the error.
controller code block
public function searchDev()
{
return view ( 'pages.MySearch');
}
public function search(Request $request)
{
$UserName = $request->input('MyName');
if($UserName != ""){
$temp = temp::where ( 'NAME', 'LIKE', '%' . $UserName . '%' )->get (['id','NAME','CONTACT','TEMP_ADDRESS']);
if (count ( $temp ) > 0)
{
/*
getting result from database
dump($temp);
return response()->json($temp);
*/
return view('pages.MySearch', [
'temp' => $temp
]);
}
else
{
return view ( 'pages.MySearch')->with('alert-danger', 'Sorry No details found');
}
}
}
view page code block
@foreach($temp as $data)
<tr>
<td> {{$data['NAME']}} </td>
<td> {{$data['CONTACT']}} </td>
<td> {{$data['TEMP_ADDRESS']}} </td>
</tr>
@endforeach
route code
Route::get('/MySearch','MyController@searchDev');
Route::post('/MySearch','MyController@search');
The error is general, but I can't debug the error what is the cause of the error. Please help!!!