這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在Larave中對所有數(shù)據(jù)表進(jìn)行獲取,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
代碼如下:
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)) { $table[] = $value; }; } // $columns[] = Schema::getColumnListing('users'); } $table = array_unique($table); dd($table); }
Schema::getColumnListing('user'); Schema::hasColumn($table, $column_name)
這里記一筆,比知道有沒有更好的方法一步獲取到當(dāng)前連接的數(shù)據(jù)庫里面的所有的表,我是用原生的sql語句show tables查出所有表,然后取出Tables_in_new_bcc_web這一列,然后才得到所有的表名,然后再去循環(huán)。
找到一個更棒的方式:
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)) { $table[] = $value; }; } } $table = array_unique($table); dd($table); }
上述就是小編為大家分享的怎么在Larave中對所有數(shù)據(jù)表進(jìn)行獲取了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
新聞標(biāo)題:怎么在Larave中對所有數(shù)據(jù)表進(jìn)行獲取-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://vcdvsql.cn/article6/ccscig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、定制開發(fā)、外貿(mào)網(wǎng)站建設(shè)、定制網(wǎng)站、用戶體驗、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容