我在看 Illuminate\Support\MessageBag类方法时,类是这样的:
use JsonSerializable;
use Illuminate\Contracts\Support\Jsonable;
....
class MessageBag implements Jsonable, JsonSerializable...
/*
* Convert the object to its JSON representation.
*/
public function toJson ($options = 0) {
return json_encode($this->jsonSerialize(), $options);
}
/*
*Convert the object into something JSON serializable.
*/
public function jsonSerialize() {
return $this->toArray();
}
请教各位前辈,toJson方法和jsonSerialize方法的区别是什么呢?什么时候会隐式调用呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这样?
谢邀!
因为我没用过larval,你可以贴出toJson方法和jsonSerialize方法的具体代码么