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