Laravel get all the database tables and structures

Source: Internet
Author: User
Tags foreach

To meet a requirement, you need to modify all the tables in the database that contain the email fields, and change the length of the inside to 128 bits. Laravel gets all the tables and then loops through the table to see if there is any email in this field. The code is as follows:

Use Illuminate\support\facades\schema;
Use DB;

Public Function Getdatabasecolumns () {
    $tables = Db::select (' Show Tables ');
    $tables = Array_column ($tables, ' tables_in_new_bcc_web ');
    $columns = [' email ', ' user_name ', ' nick_name ', ' first_name ', ' last_name '];
    DD (Schema::getconnection ());
    foreach ($tables as $key = + $value) {
        foreach ($columns as $k + $v) {
            if (Schema::hascolumn ($value, $v)) { c9/> $table [] = $value;
            };
        }
        $columns [] = schema::getcolumnlisting (' users ');
    }
    $table = Array_unique ($table);
    DD ($table);
}
Schema::getcolumnlisting (' user ');
Schema::hascolumn ($table, $column _name)

Here to remember, than to know there is no better way to get to the current connected database inside all the tables, I was using native SQL statements show tables to isolate all tables, and then remove tables_in_new_bcc_web This column before you get all the table names, and then go back to the loop.
Find a great way to:

Public Function Getdatabasecolumns () {
    $tables = array_map (' Reset ', \db::select (' SHOW tables '));
    $columns = [' email ', ' user_name ', ' nick_name ', ' first_name ', ' last_name '];
    foreach ($tables as $key = + $value) {
        foreach ($columns as $k + $v) {
            if (Schema::hascolumn ($value, $v)) { c7/> $table [] = $value;
            };
        }
    }
    $table = Array_unique ($table);
    DD ($table);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.