class TransformResponse implements Responsable
{
public $name;
public function __construct($name)
{
$this->name = $name;
}
public function toResponse($request)
{
$this->name = 'Mr. ' . $this->name;
return response(['name' => $this->name]);
}
}
-
$res = new \TransformResponse('Orocimaru');
return $res; // output { "name": "Mr. Orocimaru" }
return $res->name; // output "Orocimaru"
# expected output "Mr. Orochimaru"
-
如何获得预期的输出?
是否有权在toResponse()中进行突变?