Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

emilpapelas4@gmail.com's avatar

Cant get $question->id

I have my wall.blade where i show all surveys from Database thats works, but i also want to display the first question->id of that survey because i use a link to redirect to that survey with id and first question id.

Wall controller

$survey = Survey::where('status',1)->get();  //Will get all survey and send to view.  Works
$question = Question::where('survey_id',$survey->id)->first(); // Error Property [id] does not exist on this collection instance.

On wall blade have that link that redirect to survey.

{{ url("/offerwall/survey/".$sv->id."/".$q->id."/".$user."?hash=".md5($sv->id.$user.'FDSFERDSADFEJ$@')) }}
0 likes
17 replies
SilenceBringer's avatar

@emilpapelas4@gmail.com here

$survey = Survey::where('status',1)->get();

you get collection of surveys, not just 1 survey. That's why $survey->id returs error

if you need specific survey - use first on Survey model (or specific condition)

$survey = Survey::where('status',1)->fisrt();
emilpapelas4@gmail.com's avatar

@SilenceBringer OK now will get this error Attempt to read property "title" on bool (View: C:\xampp\htdocs\LaravelSurvey\resources\views\offerwall\wall.blade.php)

 @foreach($survey as $sv)
              <div class="flex bg-gray-200 drop-shadow-md rounded p-2 items-center mb-2">
                  <div class="bg-blue-700 w-24 h-24 rounded flex items-center justify-center">
                      <svg class="text-white w-10 h-10" data-v-6db1de90="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="rocket-launch" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-test-id="fa-icon" class="bb-text-color-white dark:bb-text-color-black bb-width-100 bb-height-100 svg-inline--fa fa-rocket-launch category-icon__fa-icon--colorized">
                      <path data-v-6db1de90="" fill="currentColor" d="M424 143.1C424 174.9 398.9 199.1 368 199.1C337.1 199.1 312 174.9 312 143.1C312 113.1 337.1 87.1 368 87.1C398.9 87.1 424 113.1 424 143.1zM368 167.1C381.3 167.1 392 157.3 392 143.1C392 130.7 381.3 119.1 368 119.1C354.7 119.1 344 130.7 344 143.1C344 157.3 354.7 167.1 368 167.1zM348.6 459.6L247.2 510.3C242.2 512.8 236.3 512.5 231.6 509.6C226.9 506.7 224 501.5 224 496V381.3C224 356.5 214.2 332.8 196.7 315.3C179.2 297.8 155.5 288 130.7 288H16C10.45 288 5.305 285.1 2.39 280.4C-.5254 275.7-.7907 269.8 1.689 264.8L52.42 163.4C63.26 141.7 85.42 127.1 109.7 127.1H207C286.9-3.743 409.5-8.542 483.9 5.255C495.6 7.41 504.6 16.45 506.7 28.07C520.5 102.5 515.7 225.1 384 304.1V402.3C384 426.6 370.3 448.7 348.6 459.6L348.6 459.6zM243.4 326.5C365.7 296.4 425.3 242.1 453.9 190.9C483.4 137.4 483.4 79.5 475.7 36.29C432.5 28.65 374.6 28.63 321.1 58.06C269 86.72 215.6 146.3 185.5 268.6C197.9 274.6 209.4 282.7 219.3 292.7C229.3 302.6 237.4 314.1 243.4 326.5zM256 470.1L334.3 430.1C345.2 425.5 352 414.5 352 402.3V322.2C324 335.7 291.5 347.5 253.6 356.1C255.2 364.9 256 373 256 381.3V470.1zM155 258.4C164.5 220.5 176.3 187.1 189.8 159.1H109.7C97.54 159.1 86.46 166.8 81.04 177.7L41.89 256H130.7C138.1 256 147.1 256.8 155 258.4H155zM166.5 470C117 519.5 .4765 511.5 .4765 511.5C.4765 511.5-7.516 394.1 41.98 345.5C76.37 311.1 132.1 311.1 166.5 345.5C200.9 379.9 200.9 435.6 166.5 470V470zM143.9 368.1C121.1 346.2 86.5 346.2 64.61 368.1C48.05 384.7 38.52 416.5 34.44 450.8C33.21 461.3 32.56 471.1 32.25 479.8C40.86 479.4 50.74 478.8 61.16 477.6C95.49 473.5 127.3 463.9 143.9 447.4C165.8 425.5 165.8 390 143.9 368.1V368.1z" class=""></path></svg>
                  </div>
                  <div class="flex flex-col px-2 mr-auto">
                      <h4 class="font-bold text-lg text-gray-900">{{$sv->title}}</h4>
                      <p class="mt-1 flex-1 font-normal text-sm text-slate-500">{{$sv->description}}</p>
                      <p class="mt-1 flex-1 font-normal text-sm text-slate-500">{{$sv->payout * 5}}</p>
                  </div>
                  
                  <a class="px-2 py-1 border bg-yellow-700 rounded text-center text-white text-sm hover:no-underline" href="{{ url("/offerwall/survey/".$sv->id."/".$q->id."/".$user."?hash=".md5($sv->id.$user.'FDSFERDSADFEJ$@')) }}" target="_blank">
                      Earn                                                                                                  
                  </a>
              </div>
            @endforeach
SilenceBringer's avatar

@emilpapelas4@gmail.com ok, you you use loop in blade - you need to use get on surveys, correct

I do not understand - survey has just 1 question?

Assuming survey has many questions

$surveys = Survey::where('status',1)->get();
$questions = Question::whereIn('survey_id', $survey->pluck('id'))->get()->groupBy('survey_id');

and in blade

@foreach($surveys as $survey)
	@foreach($questions as $question)
		{{ url("/offerwall/survey/".$survey->id."/".$question->id."/".$user."?hash=".md5($survey->id.$user.'FDSFERDSADFEJ$@')) }}
	@endforeach
@endforeach
emilpapelas4@gmail.com's avatar

@SilenceBringer i dont like u said

 @foreach($surveys as $survey)
            @foreach($questions as $question)
              <div class="flex bg-gray-200 drop-shadow-md rounded p-2 items-center mb-2">
                  <div class="bg-blue-700 w-24 h-24 rounded flex items-center justify-center">
                      <svg class="text-white w-10 h-10" data-v-6db1de90="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="rocket-launch" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-test-id="fa-icon" class="bb-text-color-white dark:bb-text-color-black bb-width-100 bb-height-100 svg-inline--fa fa-rocket-launch category-icon__fa-icon--colorized">
                      <path data-v-6db1de90="" fill="currentColor" d="M424 143.1C424 174.9 398.9 199.1 368 199.1C337.1 199.1 312 174.9 312 143.1C312 113.1 337.1 87.1 368 87.1C398.9 87.1 424 113.1 424 143.1zM368 167.1C381.3 167.1 392 157.3 392 143.1C392 130.7 381.3 119.1 368 119.1C354.7 119.1 344 130.7 344 143.1C344 157.3 354.7 167.1 368 167.1zM348.6 459.6L247.2 510.3C242.2 512.8 236.3 512.5 231.6 509.6C226.9 506.7 224 501.5 224 496V381.3C224 356.5 214.2 332.8 196.7 315.3C179.2 297.8 155.5 288 130.7 288H16C10.45 288 5.305 285.1 2.39 280.4C-.5254 275.7-.7907 269.8 1.689 264.8L52.42 163.4C63.26 141.7 85.42 127.1 109.7 127.1H207C286.9-3.743 409.5-8.542 483.9 5.255C495.6 7.41 504.6 16.45 506.7 28.07C520.5 102.5 515.7 225.1 384 304.1V402.3C384 426.6 370.3 448.7 348.6 459.6L348.6 459.6zM243.4 326.5C365.7 296.4 425.3 242.1 453.9 190.9C483.4 137.4 483.4 79.5 475.7 36.29C432.5 28.65 374.6 28.63 321.1 58.06C269 86.72 215.6 146.3 185.5 268.6C197.9 274.6 209.4 282.7 219.3 292.7C229.3 302.6 237.4 314.1 243.4 326.5zM256 470.1L334.3 430.1C345.2 425.5 352 414.5 352 402.3V322.2C324 335.7 291.5 347.5 253.6 356.1C255.2 364.9 256 373 256 381.3V470.1zM155 258.4C164.5 220.5 176.3 187.1 189.8 159.1H109.7C97.54 159.1 86.46 166.8 81.04 177.7L41.89 256H130.7C138.1 256 147.1 256.8 155 258.4H155zM166.5 470C117 519.5 .4765 511.5 .4765 511.5C.4765 511.5-7.516 394.1 41.98 345.5C76.37 311.1 132.1 311.1 166.5 345.5C200.9 379.9 200.9 435.6 166.5 470V470zM143.9 368.1C121.1 346.2 86.5 346.2 64.61 368.1C48.05 384.7 38.52 416.5 34.44 450.8C33.21 461.3 32.56 471.1 32.25 479.8C40.86 479.4 50.74 478.8 61.16 477.6C95.49 473.5 127.3 463.9 143.9 447.4C165.8 425.5 165.8 390 143.9 368.1V368.1z" class=""></path></svg>
                  </div>
                  <div class="flex flex-col px-2 mr-auto">
                      <h4 class="font-bold text-lg text-gray-900">{{$survey->title}}</h4>
                      <p class="mt-1 flex-1 font-normal text-sm text-slate-500">{{$survey->description}}</p>
                      <p class="mt-1 flex-1 font-normal text-sm text-slate-500">{{$survey->payout * 5}}</p>
                  </div>
                  
                  <a class="px-2 py-1 border bg-yellow-700 rounded text-center text-white text-sm hover:no-underline" href="{{ url("/offerwall/survey/".$survey->id."/".$question->id."/".$user."?hash=".md5($sv->id.$user.'FDSFERDSADFEJ$@')) }}" target="_blank">
                      Earn                                                                                                  
                  </a>
              </div>
            @endforeach
            @endforeach
$surveys = Survey::where('status',1)->get();         
        $questions = Question::whereIn('survey_id', $survey->pluck('id'))->get()->groupBy('survey_id');
        
        return view('offerwall.wall', compact('surveys','placement','user','questions'));

But still get Property [id] does not exist on this collection instance. (View: C:\xampp\htdocs\LaravelSurvey\resources\views\offerwall\wall.blade.php)

SilenceBringer's avatar

@emilpapelas4@gmail.com do you see highlighted row? I think it's $sv->id, because you do not have $sv

also fix

$questions = Question::whereIn('survey_id', $surveys->pluck('id'))->get()->groupBy('survey_id');
emilpapelas4@gmail.com's avatar

@SilenceBringer yes this line is highlighted

                  <a class="px-2 py-1 border bg-yellow-700 rounded text-center text-white text-sm hover:no-underline" href="{{ url("/offerwall/survey/".$survey->id."/".$question->id."/".$user) }}" target="_blank">Earn</a>

Please or to participate in this conversation.