Whatever you return from your controller, Laravel will try to convert to a string. When you return the object, the magic method of the __toString() object will be called to perform the conversion.
Therefore, when you simply return $promotion from your controller action, Laravel is about to call __toString() for it to convert it to a string for display.
In Model __toString() calls toJson() , which returns the result of json_encode . Therefore, json_encode returns false , which means that it is encountering an error.
Your dd shows that your img attribute is a stream resource . json_encode cannot encode resource , so this probably causes a crash. You must add your img attribute to the $hidden property to remove it from json_encode .
class Promotion extends Model { protected $hidden = ['img']; // rest of class }
patricus
source share