The DatabaseConstraintClass is used to retrieve information about a specific table's database constraints, including primary keys, unique keys, foreign keys, and indexes. It automatically detects the database driver (MySQL, PostgreSQL, or SQLite) and executes the appropriate queries.
To use it, instantiate the class with the target table name. You can then invoke the instance to get an associative array containing the constraint data.
Return Formats by Driver
MySQL & PostgreSQL
Returns an array with the following keys:
primary: Primary key information.unique: Unique key information.foreign: Foreign key information.index: Index information.
SQLite
Returns an array with the following keys:
primary: Primary key information (fields where pk is 1).foreign: Foreign key information (fields from, to, and table).index: Index information (field name).
use Vcian//
LaravelDBAuditor//
Queries
DatabaseConstraintClass;
// Analyze constraints for the 'users' table
$constraints = new DatabaseConstraintClass('users');
$data = $constraints();
print_r($data);