As a beginner in Laravel, I am looking to pass JSON data from my controller using vanilla JavaScript to my view blade. However, I am unsure of the steps to accomplish this.
Below is an example of my controller:
public function index(Request $request)
{
if($request->has('search'))
{
$student_data = \App\Student::where('name','LIKE','%'.$request->search.'%')->get();
}
else
{
$student_data = \App\Student::all();
}
return response()->json(array('student_data' => $student_data));
}