1

i have serialize data in my code, to make me more flexible in inputing data

but i still dont know how to displaying serialize data in blade

this is my serialize data

enter image description here

this is my controller

public function preview($id)
  {
    $form = NewForm::whereId($id)->firstOrFail();
    // return $form;

    if($form->is_published)
    {
      $data['form'] = $form;
      $data['participant'] = $form->participant;
      $data['idea'] = $form->idea;
      $data['character'] = $form->character;
      $data['link'] = $form->link;
      $data['images'] = $form->images;
      $data['finance'] = $form->finance;
      $data['competition'] = $form->competition;
      $data['competition_list'] = $form->competition_list;
      $data['audition'] = $form->audition;
      $data['confirmation'] = $form->confirmation;
      $data['survey'] = unserialize($form->survey);

      // return $data;

      $pdf = PDF::loadView('pdf.form', $data);

      return $pdf->stream('DSCX'.sprintf("%04d", $form->id).'.pdf');
    }

    return 'Proposal not published';
  }

this is my blade

<label>Survey</label>
   <p>{{ $survey->source }}</p>
</td>

when i do

unserialize($form->survey) it is returning this error unserialize(): Error at offset 0 of 251 bytes

how do i display the data? thank you

Eranda Dava
  • 89
  • 1
  • 9

1 Answers1

0

You will need to call unserialize() on that string to convert it to an appropriate array, you can then display your array properties.

Do something like this in your controller, and pass the data to your view:

$survey = unserialize($form->survey);

Then foreach through that array in your blade view:

@foreach ($survey as $line)
    <p>{{ $line }}</p>
@endforeach
Stuart
  • 6,630
  • 2
  • 24
  • 40