Is there a way to get the datatype of a database table field? Almost like a inverse of migration.
For example, if the migration of a users table column looks like
$temp = $this->newQuery()->fromQuery("SHOW FIELDS FROM ".$this->getTable()); foreach($temp as $val){ echo 'Field: '.$val->Field; echo 'Type: '.$val->Type; }
Generalizing:
DB::connection()->getDoctrineColumn($tableName, $colName)
->getType()
->getName();
It works on Laravel 5.3.
use Illuminate\Database\Schema\Builder::getColumnType()
DB::getSchemaBuilder()->getColumnType($tableName, $colName)
e.g.
DB::getSchemaBuilder()->getColumnType('user', 'age')
You may need to run
composer require doctrine/dbal
if you haven't already.