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"
-
How to get expected output?
Whether right to do mutation inside toResponse()?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire