A utility class intended to help interface with a databases' schema information in an efficient manner.
Firstly add the schema-info dependency to your projects composer file
composer.json
"require": {
...,
"shadetheartist/schema-info": "1.5.3"
}
In your terminal run composer dump-autoload
.
Secondly add the SchemaInfo service provider and facade to your projects' bootstrapping procedure via
config/app.php
'providers' => [
...,
SchemaInfo\SchemaInfoServiceProvider::class,
]
And you're set!
<?php namespace App;
use SchemaInfo\Facades\SchemaInfo;
class Example
{
public function example()
{
$schema = SchemaInfo::make();
}
public function exampleAltConnection()
{
//connect to a different database. note: only mysql databases are currently supported.
$schema = SchemaInfo::make(\DB::connection('my-alternative-connection'));
}
}
$table = $schema->table('my_table_name');
//returns a stdClass instance refecting a record from the schema info of your database.
$info = $table->info();
$table = $schema->table('my_table_name');
$column = $table->column('my_column_name');
$allColumns = $table->columns();
$column = $table->column('my_column_name');
//returns a stdClass instance refecting a record from the schema info of your database.
$column->info();
//get the table the column belongs to.
$parentTable = $column->table();