@@ -81,7 +81,7 @@ public function primary($name, ?bool $autoIncrement = true, ?bool $unsigned = tr
8181 */
8282 public function index ($ name = null )
8383 {
84- $ this ->columns [count ($ this ->columns ) - 1 ]['index ' ] = $ this ->generix_name ($ name );
84+ $ this ->columns [count ($ this ->columns ) - 1 ]['index ' ] = $ this ->genericIdentifier ($ name );
8585
8686 return $ this ;
8787 }
@@ -94,7 +94,7 @@ public function index($name = null)
9494 */
9595 public function unique ($ name = null )
9696 {
97- $ this ->columns [count ($ this ->columns ) - 1 ]['unique ' ] = $ this ->generix_name ($ name );
97+ $ this ->columns [count ($ this ->columns ) - 1 ]['unique ' ] = $ this ->genericIdentifier ($ name );
9898
9999 return $ this ;
100100 }
@@ -132,40 +132,49 @@ public function foreignId($column)
132132 * @param string $column
133133 * - [optional] Default is `id`
134134 *
135+ * @param string|null $indexName
136+ *
135137 * @return $this
136138 */
137- public function constrained ($ table = null , $ column = 'id ' )
139+ public function constrained ($ table = null , $ column = 'id ' , $ indexName = null )
138140 {
139141 // we try to use defined table name, if no name is given to the method
140- $ tableName = explode ('_ ' , $ this ->tableName );
142+ if (empty ($ table )){
143+ $ table = explode ('_ ' , $ this ->tableName )[0 ] ?? '' ;
144+ }
141145
142- return $ this ->references ($ column )->on ($ table ?? $ tableName [ 0 ] ?? '' );
146+ return $ this ->references ($ column, $ indexName )->on ($ table );
143147 }
144148
145149 /**
146150 * Creating Constraints Property
147- * @param string $referencedColumn
151+ *
152+ * @param string $columns
148153 * <code> - Parent Table References Column name </code>
149154 *
155+ * @param string|null $indexName
156+ *
150157 * @return $this
151158 */
152- public function references ($ referencedColumn )
159+ public function references ($ columns , $ indexName = null )
153160 {
154- $ this ->columns [count ($ this ->columns ) - 1 ]['references ' ] = $ referencedColumn ;
155- $ this ->columns [count ($ this ->columns ) - 1 ]['generix ' ] = $ this ->generix_name ($ referencedColumn );
161+ $ this ->columns [count ($ this ->columns ) - 1 ]['references ' ] = $ columns ;
162+ $ this ->columns [count ($ this ->columns ) - 1 ]['generix ' ] = $ this ->genericIdentifier ($ indexName ?? $ columns );
163+
156164 return $ this ;
157165 }
158166
159167 /**
160168 * Creating Constraints Property
161- * @param string $referencedTable
169+ *
170+ * @param string $table
162171 * - Table name you're referencing to
163172 *
164173 * @return $this
165174 */
166- public function on ($ referencedTable )
175+ public function on ($ table )
167176 {
168- $ this ->columns [count ($ this ->columns ) - 1 ]['on ' ] = $ referencedTable ;
177+ $ this ->columns [count ($ this ->columns ) - 1 ]['on ' ] = $ table ;
169178 return $ this ;
170179 }
171180
0 commit comments