Home > Article > PHP Framework > How to determine if a table exists in laravel
How to determine whether a table exists in laravel: 1. Use the "if (Schema::hasTable('table_name')){...}" method to detect whether a table exists; 2. If it does not exist, then Just perform the create operation.
The operating environment of this tutorial: Windows 7 system, Laravel version 5.7, DELL G3 computer.
How does laravel determine whether a table exists?
Laravel database: Determine whether the data table exists
Detect whether a table exists:
if (Schema::hasTable('table_name')) { // }
Execute the creation operation if a certain table does not exist :
if ( ! Schema::hasTable('table_name')) { // 创建数据库表的代码 }
If you want to safely drop a data table, use the following:
Schema::dropIfExists('table_name');
Related recommendations: The latest five Laravel video tutorials
The above is the detailed content of How to determine if a table exists in laravel. For more information, please follow other related articles on the PHP Chinese website!