|
8 | 8 | use GearboxSolutions\EloquentFileMaker\Database\Query\FMBaseBuilder; |
9 | 9 | use GearboxSolutions\EloquentFileMaker\Exceptions\FileMakerDataApiException; |
10 | 10 | use Illuminate\Database\Eloquent\Builder; |
| 11 | +use Illuminate\Database\Eloquent\Collection; |
11 | 12 | use Illuminate\Database\Eloquent\Model; |
12 | 13 | use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot; |
13 | 14 | use Illuminate\Database\Eloquent\Relations\Pivot; |
14 | 15 | use Illuminate\Http\File; |
15 | 16 | use Illuminate\Http\UploadedFile; |
16 | | -use Illuminate\Support\Collection; |
| 17 | +use Illuminate\Support\Collection as BaseCollection; |
17 | 18 | use Illuminate\Support\Str; |
18 | 19 |
|
19 | 20 | abstract class FMModel extends Model |
@@ -145,24 +146,19 @@ public static function createFromRecord($record) |
145 | 146 | return $instance; |
146 | 147 | } |
147 | 148 |
|
148 | | - public static function createModelsFromRecordSet(Collection $records): Collection |
| 149 | + public static function createModelsFromRecordSet(BaseCollection $records): Collection |
149 | 150 | { |
150 | | - |
151 | | - // start with an empty collection |
152 | | - $collection = collect([]); |
153 | | - |
154 | 151 | // return an empty collection if an empty collection was passed in. |
155 | 152 | if ($records->count() === 0) { |
156 | | - return $collection; |
| 153 | + return (new static())->newCollection([]); |
157 | 154 | } |
158 | 155 |
|
159 | 156 | // Records passed in weren't empty, so process the records |
160 | | - foreach ($records as $record) { |
161 | | - $model = static::createFromRecord($record); |
162 | | - $collection->push($model); |
163 | | - } |
| 157 | + $mappedRecords = $records->map(function ($record) { |
| 158 | + return static::createFromRecord($record); |
| 159 | + }); |
164 | 160 |
|
165 | | - return $collection; |
| 161 | + return (new static())->newCollection($mappedRecords->all()); |
166 | 162 | } |
167 | 163 |
|
168 | 164 | /** Fill in data for this existing model with record data from FileMaker |
@@ -396,7 +392,7 @@ protected function performInsert(Builder $query) |
396 | 392 | /** |
397 | 393 | * Strip out containers and read-only fields to prepare for a write query |
398 | 394 | * |
399 | | - * @return Collection |
| 395 | + * @return BaseCollection |
400 | 396 | */ |
401 | 397 | public function getAttributesForFileMakerWrite() |
402 | 398 | { |
|
0 commit comments