Home  >  Article  >  PHP Framework  >  How to determine if a table exists in laravel

How to determine if a table exists in laravel

藏色散人
藏色散人Original
2021-12-22 11:25:264271browse

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.

How to determine if a table exists in laravel

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn