vendredi 21 août 2015

Gettting stdClass object as object(stdClass)[330] Laravel 5

I am working on laravel 5 and when I am trying to extract the values which I send from controller to View then I get the error because of the output.

Here is the code

public function quiz($id){ $data=array(); $allQuestions=$data['questions']=DB::table("question") ->select("question.*")
->join("client_question","client_question.question","=","question.id") ->where("client_question.client","=",$id) ->get(); if($allQuestions){
foreach($allQuestions as $question){ $data['questions']['answers'][$question->id]=DB::table("answer")->where("question_id","=",$question->id)->get(); } }
//echo "<pre>"; //print_r($data);die; return View('client.quiz', compact('data'));
}
If I print $data here then

outpu is like :

 [questions] => Array
    (
        [0] => stdClass Object
            (
                [id] => 38
                [question] => tttttwwwwwwww edited
                [description] => tttttqqqqqqqqqqqq edited
                [category] => 1
                [lang] => en
                [type] => radios
                [choices] => MC
                [created_at] => 2015-08-19 11:27:54
                [updated_at] => 2015-08-20 09:08:24
            )

But when I print $data on view in .blade file then Output Is like : `

array (size=1)
  'questions' => 
array (size=8)
  0 => 
    object(stdClass)[330]
      public 'id' => int 38
      public 'question' => string 'tttttwwwwwwww edited' (length=20)
      public 'description' => string 'tttttqqqqqqqqqqqq edited' (length=24)
      public 'category' => int 1
      public 'lang' => string 'en' (length=2)
      public 'type' => string 'radios' (length=6)
      public 'choices' => string 'MC' (length=2)
      public 'created_at' => string '2015-08-19 11:27:54' (length=19)
      public 'updated_at' => string '2015-08-20 09:08:24' (length=19)`

In this case point to be note is object(stdClass)[330] which is different format. Is anyone have solution for this please ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NJw96d
via IFTTT

Aucun commentaire:

Enregistrer un commentaire