Table of contents
For whatsoever reason, you may want to check the existence of a table in your database. You can easily achieve this by using one of Laravel's schema builder method hasTable()
. The Laravel schema builder hasTable()
method accepts one argument, the name of the table to check.
Â
Previously I have functionality that need to check the table if exists before I generate a new table using my custom CRUD generator.
Â
Maybe you need to check our tutorial on how to generate table fields just visit here. We use the model class to extract the table and call the fields.
Â
Syntax:
if (Schema::hasTable('table_name'))
{
// Do something if exists
}
Â
That's a brief tip for checking table exists using Laravel. I hope it helps.
Cheers :)
Read next