使用 Eloquent 从数据库中获取元信息

Get meta information from the database with Eloquent

我可能在这里遗漏了一些简单的东西,但是如何使用 Laravel/Eloquent 获取 table 的主键?当我执行以下命令时,我在直接在数据库上执行时收到语法错误错误。

$primarykey = DB::table('table')->whereRaw('SHOW KEYS FROM table WHERE Key_name = "PRIMARY"')->get();

我用下面的代码试了一下,成功了。

$primarykey = DB::select('SHOW KEYS FROM users WHERE Key_name = "PRIMARY"');

我使用了 select 没有 get 方法的数据库,因为它 returns 这样的数组

[
     {#3558
       +"Table": "users",
       +"Non_unique": 0,
       +"Key_name": "PRIMARY",
       +"Seq_in_index": 1,
       +"Column_name": "id",
       +"Collation": "A",
       +"Cardinality": 1,
       +"Sub_part": null,
       +"Packed": null,
       +"Null": "",
       +"Index_type": "BTREE",
       +"Comment": "",
       +"Index_comment": "",
     },
   ]

因此,如果您发现其中有任何问题,请尝试告诉我。 谢谢