-
From laravel 4 to 9. It seems there has been no checker for the schema to check foreign keys. I was hoping from v4 to 9 to have something like this. But it seems until now, there is no function. I need help, The Function I has hoping for: Schema::hasForeign('<table name>', ['<column name>']); // that will return true or false |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It's a bit hacky, but this may be a solution. $doctrineTable = Schema::getConnection()->getDoctrineSchemaManager()->listTableDetails('table_name');
$doctrineTable->hasForeignKey('foreignKeyName'); |
Beta Was this translation helpful? Give feedback.
-
With With I agree it's a little too much for something so simple, and we cannot add macro's to the Schema builder. |
Beta Was this translation helpful? Give feedback.
With
getForeignKeyColumns()
you can get an array of columns who are involved in a foreign key constraint.With
getForeignKeys()
you get an arrray ofForeignKeyConstraint
which has a methodgetLocalColumns
with an array you can use to check if the column you want is involved.I agree it's a little too much for something so simple, and we cannot add macro's to the Schema builder.