The syntax seems good but I would suggest you to use the
compact method to send data to your view.
return view('home', compact('surveys'));
Thank you @faisal I tried that but it didn't seem to work either :) I'm still getting the Undefined variable $surveys error message.
The use for compact or not is a question of taste and in this case not part of your problem ;)
$surveys = DB::select('select name, value from surveys'); you create a query builder but didn't execute it. I did check the documentation and see you miss the
I suspect if you update the code to
$surveys = DB::select('select name, value from surveys')->get(); that you will receive the results.
ps. I have updated your post to make the code blocks more readable.
Thank you for your response and for updating my code blocks. I am new to this platform as well and wasn't sure how to do it.
I tried adding the ->get(); method to the end of my query builder, but am met with the same undefined variable error. I am not sure what I could be missing!
HI @shazam7734 ,
Strangely, you are still getting the error. I suggest you to please check the name of your view once again and also the variable name.
Try debugging the data stored in the variable before sending it to the view.
And finally, try to load the view without the
foreach loop just to make sure that you are accessing the correct view.
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us