• Register
0 votes

Problem :

I am trying to learn the pSQL. I recently moved my Laravel App from the MySQL to pSQL. But now I keep on getting below error.

“The Response content must be a string or object implementing __toString(), "boolean" given.”

I have the API that was returning my promotion before but now it only returns the above error.

Can anyone suggest me solution on above error ?

8 4 2
2,300 points

1 Answer

0 votes

Solution :

If you are returning something from your controller then the Laravel will convert it to the string. If you return the object then your object's __toString() the magic method will be automatically invoked to make the required conversion.

So when you just try to return your $promotion from the controller action then the Laravel is going to call the magic method __toString() on it and it will be converted to the string to display.

On your Model__toString() calls your toJson(), which will return you the result of your json_encode. So now the json_encode is returning a false, it clearly suggests that it is running into the error.

I guess your dd must be showing that your img attribute is the stream resourcejson_encode cannot readily encode your resource, so this is the main reason behind the failure. So you must add your img attribute to your $hidden property to try to remove it from your json_encode as shown below

class Promotion extends Model
    protected $hidden = ['img'];
    // rest of your class


5 2 1
4,980 points

Related questions

0 votes
1 answer 1.6K views
Problem : I got stuck on below error I am trying to configure my SMTP mail on laravel “Expected response code 250 but got code "530", with message "530 5.7.1 authentication required "” Below is the configuration on .env MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io ... I have tried to authenticate my SMTP on the env but I keep facing the above error so for now I am stuck on that error.
asked Feb 4 jwilliam 3.9k points
0 votes
1 answer 41 views
Problem : Facing migration error on Laravel 5.4 with php artisan make:auth command as follows: syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
asked Nov 13, 2019 peterlaw 6.9k points
1 vote
1 answer 38 views
Problem: I am very new to PHP and Laravel. I am trying my luck in programming. Please find my code as below for your reference: protected function allcredentials(Request $request) { $admin=admin::where('email',$request->email)->first(); if(count($admin)) { if( ... ): Parameter must be an array or an object that implements Countable". Kindly give me the quick fix on my above PHP related error.
asked May 29 Martin K 6.6k points
0 votes
1 answer 200 views
Problem : I am currently using the Mac OS Yosemite and Laravel 5.0. I am new to Laravel 5.0. In the local environment whenever I run the below command php artisan migrate I always encounter below error : “Access denied for user 'homestead'@'localhost' (using password: YES)” I am unable to fix above error. Any clue to fix the above error?
asked Feb 13 mphil 2.3k points