I'm trying to check if a column in a database is unique.
How do I do this in PHP/Laravel?
The Schema Builder doesn't provide anything. I also looked into the DB::
facade. I also tried a general search for "php column is unique"
My purpose is to take a table, add a 'site_id'
column, and then make all the unique columns, say unique(email)
, become unique([email, site_id])
Using @icecub comment - There was no 'PHP' way of getting the data, I needed to use MySQL directly
$indexList = DB::select(DB::raw("SHOW INDEXES FROM $tableName WHERE NOT Non_unique and Key_Name <> 'PRIMARY'"));