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