Object of class stdClass could not be converted to string - laravel

后端 未结 6 1147
野性不改
野性不改 2021-02-18 17:04

I am following this documentation

to implement export to Excel in my laravel 4 project.

So am trying to generate excel file from array like this:



        
6条回答
  •  梦如初夏
    2021-02-18 17:34

    I was recieving the same error when I was tring to call an object element by using another objects return value like;

    $this->array1 = a json table which returns country codes of the ip
    $this->array2 = a json table which returns languages of the country codes
    
    $this->array2->$this->array1->country;// Error line
    

    The above code was throwing the error and I tried many ways to fix it like; calling this part $this->array1->country in another function as return value, (string), taking it into quotations etc. I couldn't even find the solution on the web then i realised that the solution was very simple. All you have to do it wrap it with curly brackets and that allows you to target an object with another object's element value. like;

    $this->array1 = a json table which returns country codes of the ip
    $this->array2 = a json table which returns languages of the country codes
    
    $this->array2->{$this->array1->country};
    

    If anyone facing the same and couldn't find the answer, I hope this can help because i spend a night for this simple solution =)

提交回复
热议问题