Skip to content

Commit 2fc69cb

Browse files
Merge pull request #295 from finiteinfinity/add_support_for_including_columns
Add support for column lists in base models
2 parents 75111e5 + fe140be commit 2fc69cb

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

config/models.php

+13
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@
395395
*/
396396
'with_property_constants' => false,
397397

398+
/*
399+
|--------------------------------------------------------------------------
400+
| Optionally includes a full list of columns in the base generated models,
401+
| which can be used to avoid making calls like
402+
|
403+
| ...
404+
| \Illuminate\Support\Facades\Schema::getColumnListing
405+
| ...
406+
|
407+
| which can be slow, especially for large tables.
408+
*/
409+
'with_column_list' => false,
410+
398411
/*
399412
|--------------------------------------------------------------------------
400413
| Disable Pluralization Name

src/Coders/Model/Factory.php

+7
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ protected function body(Model $model)
455455
$body .= $this->class->field('snakeAttributes', false, ['visibility' => 'public static']);
456456
}
457457

458+
if ($model->usesColumnList()) {
459+
$properties = array_keys($model->getProperties());
460+
461+
$body .= "\n";
462+
$body .= $this->class->field('columns', $properties);
463+
}
464+
458465
if ($model->hasCasts()) {
459466
$body .= $this->class->field('casts', $model->getCasts(), ['before' => "\n"]);
460467
}

src/Coders/Model/Model.php

+5
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ public function usesPropertyConstants()
12101210
return $this->config('with_property_constants', false);
12111211
}
12121212

1213+
public function usesColumnList()
1214+
{
1215+
return $this->config('with_column_list', false);
1216+
}
1217+
12131218
/**
12141219
* @return int
12151220
*/

0 commit comments

Comments
 (0)