@@ 85-96 (lines=12) @@ | ||
82 | * @param mixed $transformer |
|
83 | * @return FractalItem |
|
84 | */ |
|
85 | protected function transformModel( Model $model, $transformer = null ):FractalItem |
|
86 | { |
|
87 | $transformer = $transformer ?: $model::transformer(); |
|
88 | ||
89 | if ( is_null( $transformer ) ) { |
|
90 | return new FractalItem( $model, function () use ( $model ) { |
|
91 | return $model->toArray(); |
|
92 | } ); |
|
93 | } |
|
94 | ||
95 | return $this->transformData( $model, new $transformer( $model ), $model->getTable() ); |
|
96 | } |
|
97 | ||
98 | /** |
|
99 | * Transform a collection of Eloquent models. |
|
@@ 105-117 (lines=13) @@ | ||
102 | * @param mixed $transformer |
|
103 | * @return FractalCollection |
|
104 | */ |
|
105 | protected function transformCollection( Collection $collection, $transformer = null ):FractalCollection |
|
106 | { |
|
107 | $model = $this->resolveModel( $collection ); |
|
108 | $transformer = $transformer ?: $model::transformer(); |
|
109 | ||
110 | if ( is_null( $transformer ) ) { |
|
111 | return new FractalCollection( $collection, function () use ( $collection ) { |
|
112 | return $collection->toArray(); |
|
113 | } ); |
|
114 | } |
|
115 | ||
116 | return $this->transformData( $collection, new $transformer( $model ), $model->getTable() ); |
|
117 | } |
|
118 | ||
119 | /** |
|
120 | * Transform an Eloquent builder. |