Sql 将某些关系列移动或复制到根目录
所以我有这个雄辩的Sql 将某些关系列移动或复制到根目录,sql,laravel,eloquent,Sql,Laravel,Eloquent,所以我有这个雄辩的 $table_data = article::with('comments','authors','categories')->get(); 它将返回这种输出 id:"169" title:"test" content:"test content" {id: 178, id_article: 169, id_tempat: 1, id_bidang: null,…} {id: 176, id_article: 169, name: "Pendidikan ", tin
$table_data = article::with('comments','authors','categories')->get();
它将返回这种输出
id:"169"
title:"test"
content:"test content"
{id: 178, id_article: 169, id_tempat: 1, id_bidang: null,…}
{id: 176, id_article: 169, name: "Pendidikan ", tingkat: 8, tempat: "IKIP PGRI Pontinak",…}
created_at:"2018-02-10 01:50:06"
updated_at:"2018-02-10 01:50:06"
比如说我想拉出name:“pendididikan”
,如果我想访问它,就需要使用$table.categories.name
,但我想把它放在根上,作为categories\u name:“pendididikan”
,这样就可以了
id:"169"
title:"test"
content:"test content"
categories_name:"pendidikan"
{id: 178, id_article: 169, id_tempat: 1, id_bidang: null,…}
{id: 176, id_article: 169, name: "Pendidikan ", tingkat: 8, tempat: "IKIP PGRI Pontinak",…}
created_at:"2018-02-10 01:50:06"
updated_at:"2018-02-10 01:50:06"
那么如何做到这一点呢?您可以这样做:
$categories_name = $table_data->categories->name;
我想避免它。。。然后把那些$table_data->categories->name;为$table\u data->categories\u name;类似于执行SELECT AS的操作