Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Builder pluck() does not work with column name with space #31298

Closed
shadoWalker89 opened this issue Jan 30, 2020 · 0 comments
Closed

Query Builder pluck() does not work with column name with space #31298

shadoWalker89 opened this issue Jan 30, 2020 · 0 comments
Labels

Comments

@shadoWalker89
Copy link
Contributor

  • Laravel Version: 6.12.0
  • PHP Version: 7.2.14
  • Database Driver & Version: Mysql 5.6.31

Description:

When using the query builder to pluck some column with a space an error will occur.
For exemple

NoteRow::pluck('Identifiant groupe');

Will give this error

ErrorException : Undefined property: stdClass::$groupe`
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2330
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2302
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:687

I found the source of the bug in this method stripTableForPluck() of the query builder

return is_null($column) ? $column : last(preg_split('~\.| ~', $column));

As you can see to remove the table name from the column the method is splitting by dot or space and then take the last item.
I know that the regex should check for space not within `` because that is used to allow for having column names with space but i do not know how to update the regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants