@@ -28,13 +28,14 @@ public function id($name = 'id')
2828 */
2929 public function primary ()
3030 {
31- $ name = $ this ->columns [0 ]['name ' ] ?? 'id ' ;
32- $ type = $ this ->columns [0 ]['type ' ] ?? 'integer ' ;
31+ $ lastIndex = array_key_last ($ this ->columns );
32+ $ name = $ this ->columns [$ lastIndex ]['name ' ] ?? 'id ' ;
33+ $ type = $ this ->columns [$ lastIndex ]['type ' ] ?? 'integer ' ;
3334
34- // unset first element in columns array
35+ // unset the element in columns
3536 // since we're trying to create an auto incrementing primary key
36- // for the first column in the schema collection.
37- unset($ this ->columns [0 ]);
37+ // for the column in the schema collection.
38+ unset($ this ->columns [$ lastIndex ]);
3839
3940 return $ this ->addColumn ($ name , $ type , [
4041 'primary ' => "PRIMARY " ,
@@ -101,10 +102,9 @@ public function constrained($table = null, $column = 'id', $indexName = null)
101102 */
102103 public function references ($ columns , $ indexName = null )
103104 {
104- $ this ->columns [count ($ this ->columns )]['references ' ] = $ columns ;
105- $ this ->columns [count ($ this ->columns )]['generix ' ] = $ this ->genericIdentifier (
106- $ indexName ?? $ columns
107- );
105+ $ lastIndex = array_key_last ($ this ->columns );
106+ $ this ->columns [$ lastIndex ]['references ' ] = $ columns ;
107+ $ this ->columns [$ lastIndex ]['generix ' ] = $ this ->genericIdentifier ($ indexName );
108108
109109 return $ this ;
110110 }
@@ -119,7 +119,8 @@ public function references($columns, $indexName = null)
119119 */
120120 public function on ($ table )
121121 {
122- $ this ->columns [count ($ this ->columns )]['on ' ] = $ table ;
122+ $ lastIndex = array_key_last ($ this ->columns );
123+ $ this ->columns [$ lastIndex ]['on ' ] = $ table ;
123124 return $ this ;
124125 }
125126
@@ -131,7 +132,8 @@ public function on($table)
131132 */
132133 public function onDelete ($ action )
133134 {
134- $ this ->columns [count ($ this ->columns )]['onDelete ' ] = $ action ;
135+ $ lastIndex = array_key_last ($ this ->columns );
136+ $ this ->columns [$ lastIndex ]['onDelete ' ] = $ action ;
135137 return $ this ;
136138 }
137139
@@ -143,7 +145,8 @@ public function onDelete($action)
143145 */
144146 public function onUpdate ($ action )
145147 {
146- $ this ->columns [count ($ this ->columns )]['onUpdate ' ] = $ action ;
148+ $ lastIndex = array_key_last ($ this ->columns );
149+ $ this ->columns [$ lastIndex ]['onUpdate ' ] = $ action ;
147150 return $ this ;
148151 }
149152
@@ -154,7 +157,8 @@ public function onUpdate($action)
154157 */
155158 public function unsigned ()
156159 {
157- $ this ->columns [count ($ this ->columns )]['unsigned ' ] = true ;
160+ $ lastIndex = array_key_last ($ this ->columns );
161+ $ this ->columns [$ lastIndex ]['unsigned ' ] = true ;
158162 return $ this ;
159163 }
160164
@@ -166,7 +170,8 @@ public function unsigned()
166170 */
167171 public function default ($ value )
168172 {
169- $ this ->columns [count ($ this ->columns )]['default ' ] = $ value ;
173+ $ lastIndex = array_key_last ($ this ->columns );
174+ $ this ->columns [$ lastIndex ]['default ' ] = $ value ;
170175 return $ this ;
171176 }
172177
@@ -178,7 +183,8 @@ public function default($value)
178183 */
179184 public function nullable ()
180185 {
181- $ this ->columns [count ($ this ->columns )]['nullable ' ] = true ;
186+ $ lastIndex = array_key_last ($ this ->columns );
187+ $ this ->columns [$ lastIndex ]['nullable ' ] = true ;
182188
183189 return $ this ;
184190 }
@@ -191,7 +197,8 @@ public function nullable()
191197 */
192198 public function index ($ name = null )
193199 {
194- $ this ->columns [count ($ this ->columns )]['index ' ] = $ this ->genericIdentifier ($ name );
200+ $ lastIndex = array_key_last ($ this ->columns );
201+ $ this ->columns [$ lastIndex ]['index ' ] = $ this ->genericIdentifier ($ name );
195202
196203 return $ this ;
197204 }
@@ -204,7 +211,8 @@ public function index($name = null)
204211 */
205212 public function unique ($ name = null )
206213 {
207- $ this ->columns [count ($ this ->columns )]['unique ' ] = $ this ->genericIdentifier ($ name );
214+ $ lastIndex = array_key_last ($ this ->columns );
215+ $ this ->columns [$ lastIndex ]['unique ' ] = $ this ->genericIdentifier ($ name );
208216
209217 return $ this ;
210218 }
0 commit comments