JellyBool好~ 当我做到最后字段映射的时候出现这样的错误
"message": “Argument 1 passed to App\Api\Transformers\LessonTransformer::transform() must be an instance of App\Api\Transformers\Lesson, instance of App\Lesson given, called in D:\xampp\htdocs\laravistapi\vendor\league\fractal\src\Scope.php on line 373 and defined”,
“status_code”: 500,
“debug”: {
“line”: 9,
“file”: “D:\xampp\htdocs\laravistapi\app\Api\Transformers\LessonTransformer.php”,
“class”: “ErrorException”,
“trace”: [
/**
* Transformer Abstract
*
* All Transformer classes should extend this to utilize the convenience methods
* collection() and item(), and make the self::$availableIncludes property available.
* Extend it and add a `transform()` method to transform any default or included data
* into a basic array.
*/
这些都是开源作者偷懒吧,这样做也 OK。但是也明白一点是,即使是这样:Transformer 这一层还是很有意义的,想象这样一个场景:如果说你没有这个 Transformer,直接用的数据库字段的话,万一某一天你需要修改你的数据库字段,这个时候难道你要通知所有的 API 使用者去改他们代码中的 API 字段么?