I've got a legacy codebase making use of the illuminate database components. From the documentation its apparent I should be able to detect presence of a table in the underlying database using the Schema component.
This is my attempt
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
$schema = new SchemaBuilder(Database::getFactory()->getConnection());
I then run some tests on this.
print_r(get_class_methods($schema));
// outputs
Array ( [0] => __construct [1] => hasTable [2] => hasColumn [3] => getColumnListing [4] => table [5] => create [6] => drop [7] => dropIfExists [8] => rename [9] => getConnection [10] => setConnection [11] => blueprintResolver )
So seems happy enough.
Then.
$schema->hasTable('users');
and I get the following error
PHP message: PHP Fatal error: Call to a member function compileTableExists() on null in
I worked this out in the end.
$schema_builder = $capsule->connection()->getSchemaBuilder();
if($schema_builder->hasTable('users'))
echo 'table found';
else
echo 'table not found';