Sign Up

Sign In

Forget Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

Developers Map

how to get multiple column with pluck function in laravel

  • 1

Laravel is a most common framework. it is very easy to use and learn.if when we want to get selected column like id and name then we use pluck function. if we want to get more column from database using pluck function then use below code.

Use Below Code :
$data = DB::table("TABLE_NAME")
                 ->select("id", DB::raw("CONCAT(column_one, ' ', column_second) as result"))
                 ->orderBy('result','asc')
                 ->where('condition')
                 ->pluck("result", "id")->toArray();  

Example :
$data = DB::table("users")
                 ->select("id", DB::raw("CONCAT(first_name, ' ', last_name) as first_name"))
                 ->orderBy('first_name','asc')
                 ->where('id',Auth::user()->id)
                 ->pluck("first_name", "id")->toArray(); 
Leave an answer

Leave an answer

Browse