0

Hello everyone i am having some trouble with laravel DB class

    $arr = ['onoma', 'epitheto'];

    $data = "'".implode("', '", $arr) . "'";

    $content =  DB::table($name)->pluck($data);

When i do it manually like

$content = DB::table($name)->pluck('onoma','epitheto');

Everything is working fine. But with implode() functions i get this error

Column not found: 1054 Unknown column ''onoma', 'epitheto'' in 'field list' (SQL: select 'onoma', 'epitheto' from xrister)

3
  • try once $data = "'".implode("','", $arr)."'"; remove all the spaces Commented Mar 2, 2017 at 7:46
  • Again im getting same error 'Column not found: 1054 Unknown column ''onoma','epitheto'' in 'field list' (SQL: select 'onoma','epitheto' from xrister)' Commented Mar 2, 2017 at 7:49
  • did you removed all spaces? Commented Mar 2, 2017 at 7:50

2 Answers 2

3

In the example that works fine you are passing 2 arguments to that method call.

pluck($column, $key) 2 separate arguments

pluck('column', 'key') 2 separate strings

In the one that doesn't work you are passing a single string as 1 argument. You are telling pluck to use the single column named 'onoma','epitheto' for some reason.

pluck("'onoma', 'epitheto'") 1 string, 1 argument

Sign up to request clarification or add additional context in comments.

Comments

1

If you're using PHP 5.6 + then you can use the splat operator:

 $arr = ['onoma', 'epitheto'];

 $content =  DB::table($name)->pluck(...$arr);

If not then you can do:

 $arr = ['onoma', 'epitheto'];

 $content = call_user_func_array([ DB::table($name), 'pluck' ], $arr);

1 Comment

Thank you very much it works with the splat operator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.