In Laravel, you can check if a database table exists using the Schema
facade.
Here’s an example:
use Illuminate\Support\Facades\Schema;
if (Schema::hasTable('table_name')) {
// Do something if the table exists
} else {
// Do something else if the table doesn't exist
}
If the table exists, the hasTable()
method will return true
, otherwise it will return false
.