Repository navigation
|
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 |
Answered by
henzeb
Jul 27, 2022
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'); |
1 reply
|
With With I agree it's a little too much for something so simple, and we cannot add macro's to the Schema builder. |
1 reply
Answer selected by
JenuelDev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With
getForeignKeyColumns()you can get an array of columns who are involved in a foreign key constraint.With
getForeignKeys()you get an arrray ofForeignKeyConstraintwhich has a methodgetLocalColumnswith 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.