Support the ongoing development of Laravel.io →
Database Forms Laravel
Last updated by @tvbeek 1 year ago.
0

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'));
0

Thank you @faisal I tried that but it didn't seem to work either :) I'm still getting the Undefined variable $surveys error message.

0
moderator

Hello @shazam7734

The use for compact or not is a question of taste and in this case not part of your problem ;)

With $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 ->get() part.

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.

0

Hi @tvbeek

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!

0
Solution

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.

0
Solution selected by @shazam7734

Hi @faisal

Thank you for your sound suggestions. I have managed to work out the issue :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sarah shazam7734 Joined 25 Jul 2022

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.