Eloquent get only one column as an array

前端 未结 5 2068
时光说笑
时光说笑 2020-12-08 01:39

How to get only one column as one dimentional array in laravel 5.2 using eloquent?

I have tried:

$array = Word_relation::select(\'word_two\')->wh         


        
5条回答
  •  抹茶落季
    2020-12-08 02:06

    You can use the pluck method:

    Word_relation::where('word_one', $word_id)->pluck('word_two')->toArray();
    

    For more info on what methods are available for using with collection, you can you can check out the Laravel Documentation.

提交回复
热议问题