• $roles = Role::all()->keyBy('name')->toArray();

  • //如果不是使用Eloquent

  • $roles = collect(DB::table('role')->get())->keyBy('name')->toArray();

下面是一些常用的 把查询结果数组显示的一些方法

DB::table("user_cash_account")->where("user_id",$user_id)->first()->get_object_vars();