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

How to determine if a table exists in laravel

藏色散人
Release: 2021-12-22 11:25:26
Original
4609 people have browsed it

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'))
{
    //
}
Copy after login

Execute the creation operation if a certain table does not exist :

if ( ! Schema::hasTable('table_name')) {
    // 创建数据库表的代码
}
Copy after login

If you want to safely drop a data table, use the following:

Schema::dropIfExists('table_name');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template