Skip to content

Commit 6f0a710

Browse files
Merge pull request #196 from reliese/override-model-names
Provide facility to manually override generated model names
2 parents d0db52a + d87cc1f commit 6f0a710

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

config/models.php

+20
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,26 @@
321321

322322
'lower_table_name_first' => false,
323323

324+
/*
325+
|--------------------------------------------------------------------------
326+
| Model Names
327+
|--------------------------------------------------------------------------
328+
|
329+
| By default the generator will create models with names that match your tables.
330+
| However, if you wish to manually override the naming, you can specify a mapping
331+
| here between table and model names.
332+
|
333+
| Example:
334+
| A table called 'billing_invoices' will generate a model called `BillingInvoice`,
335+
| but you'd prefer it to generate a model called 'Invoice'. Therefore, you'd add
336+
| the following array key and value:
337+
| 'billing_invoices' => 'Invoice',
338+
*/
339+
340+
'model_names' => [
341+
342+
],
343+
324344
/*
325345
|--------------------------------------------------------------------------
326346
| Relation Name Strategy

src/Coders/Model/Model.php

+7
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ public function getQualifiedUserClassName()
521521
*/
522522
public function getClassName()
523523
{
524+
// Model names can be manually overridden by users in the config file.
525+
// If a config entry exists for this table, use that name, rather than generating one.
526+
$overriddenName = $this->config('model_names.' . $this->getTable());
527+
if ($overriddenName) {
528+
return $overriddenName;
529+
}
530+
524531
if ($this->shouldLowerCaseTableName()) {
525532
return Str::studly(Str::lower($this->getRecordName()));
526533
}

0 commit comments

Comments
 (0)