Skip to content

Commit

Permalink
Merge pull request #295 from finiteinfinity/add_support_for_including…
Browse files Browse the repository at this point in the history
…_columns

Add support for column lists in base models
  • Loading branch information
finiteinfinity authored Sep 26, 2024
2 parents 75111e5 + fe140be commit 2fc69cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@
*/
'with_property_constants' => false,

/*
|--------------------------------------------------------------------------
| Optionally includes a full list of columns in the base generated models,
| which can be used to avoid making calls like
|
| ...
| \Illuminate\Support\Facades\Schema::getColumnListing
| ...
|
| which can be slow, especially for large tables.
*/
'with_column_list' => false,

/*
|--------------------------------------------------------------------------
| Disable Pluralization Name
Expand Down
7 changes: 7 additions & 0 deletions src/Coders/Model/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ protected function body(Model $model)
$body .= $this->class->field('snakeAttributes', false, ['visibility' => 'public static']);
}

if ($model->usesColumnList()) {
$properties = array_keys($model->getProperties());

$body .= "\n";
$body .= $this->class->field('columns', $properties);
}

if ($model->hasCasts()) {
$body .= $this->class->field('casts', $model->getCasts(), ['before' => "\n"]);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Coders/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,11 @@ public function usesPropertyConstants()
return $this->config('with_property_constants', false);
}

public function usesColumnList()
{
return $this->config('with_column_list', false);
}

/**
* @return int
*/
Expand Down

0 comments on commit 2fc69cb

Please sign in to comment.