Skip to content

Commit dd3d1af

Browse files
author
Brian Faust
authored
Extract columnName function into Column::columnName (#621)
1 parent f0eddb2 commit dd3d1af

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/Models/Column.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Blueprint\Models;
44

5+
use Illuminate\Support\Str;
6+
57
class Column
68
{
79
private $modifiers;
@@ -61,4 +63,13 @@ public function isUnsigned()
6163
{
6264
return in_array('unsigned', $this->modifiers);
6365
}
66+
67+
public static function columnName($qualifiedName)
68+
{
69+
if (Str::contains($qualifiedName, '.')) {
70+
return Str::after($qualifiedName, '.');
71+
}
72+
73+
return $qualifiedName;
74+
}
6475
}

src/Models/Statements/EloquentStatement.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Blueprint\Models\Statements;
44

5+
use Blueprint\Models\Column;
56
use Illuminate\Support\Str;
67

78
class EloquentStatement
@@ -84,7 +85,7 @@ public function output(string $controller_prefix, string $context, bool $using_v
8485
$code = '$' . Str::camel($model);
8586
$code .= ' = ';
8687
$code .= $model;
87-
$code .= '::find($' . $this->columnName($this->reference()) . ');';
88+
$code .= '::find($' . Column::columnName($this->reference()) . ');';
8889
}
8990

9091
if ($this->operation() === 'delete') {
@@ -100,16 +101,6 @@ public function output(string $controller_prefix, string $context, bool $using_v
100101
return $code;
101102
}
102103

103-
// TODO: Share this so all other places can use it (Column::columnName($qualifiedName))
104-
private function columnName($value)
105-
{
106-
if (Str::contains($value, '.')) {
107-
return Str::after($value, '.');
108-
}
109-
110-
return $value;
111-
}
112-
113104
private function usesQualifiedReference()
114105
{
115106
return Str::contains($this->reference(), '.');

0 commit comments

Comments
 (0)