Eloquent groupBy make SQLSTATE[42000] with valid SQL query in Laravel 5.3
Faced same problem with laravel 5.3
They are trying to enforce strict query writing came with mysql-5.7
However to disabled this just go to config/database.php
and change strict
flag
'mysql' => [
.
.
.
'strict' => false,
//'strict' => true,
.
.
],
Hope this will solve your problem too.
PS - For details on strict query writing refer to @Shadow's answer
Laravel5: SQLSTATE[42000]: Syntax error or access violation: 1055
You need a different approach. Get all sells and items from the database and then group them:
$buyLists = Sell::join('items', 'sells.item_id', '=', 'items.item_id')
->select('sells.*', 'items.item_title')
->whereDate('sells.created_at', $timeCheck)
->get();
$groupedBuyLists = $buyLists->groupBy('ticket_number');
foreach($groupedBuyLists as $ticketNumber => $sells) {
$title = implode(', ', $sells->pluck('item_title')->all());
foreach($sells as $sell) {
// $sell->status
}
}
For items
you should use a relationship and eager loading instead of a JOIN
.
Laravel Eloquent GroupBy throwing SQL error
Change your query to a query builder query
DB::table('crawl_results')->where('user_id', Auth::id())->where('website_id', $scanID)->where('item_state', '!=' , 'OK')->groupby('destination_url')->paginate(30);
It should work fine.
In documentation it is mentioned that GROUP BY can not be executed efficiently in pagination
Currently, pagination operations that use a groupBy statement cannot
be executed efficiently by Laravel. If you need to use a groupBy with
a paginated result set, it is recommended that you query the database
and create a paginator manually.
Laravel error when get data from mySQL using groupBy
This is caused by MySQL's strict mode. Change strict
to false in your config/database.php
file.
When you open the file, in the mysql
array, set strict => false
. After you disable MySQL's strict mode it shouldn't show the error anymore.
Related Topics
Setting a Cookie in an Ajax Request
PHP MySQL SQL Parser (Insert and Update)
How to Set the Value of a Textbox Through PHP
Simple: How to Replace "All Between" with PHP
How to Get Month from Date in MySQL
Codeigniter "Flashdata" Doesn't Work
Warning: MySQLi_Query() Expects at Least 2 Parameters, 1 Given. What
Query on a Many-To-Many Relationship Using Doctrine with Symfony2
How to Extract Http Links from a Paragraph and Store Them in a Array on PHP
Cannot Initialize Mbstring with PHP 7
Why Doesn't PHP Dom Include Slash on Self Closing Tags
What Do \R and \N Mean in PHP (And Other Languages)
How to Put a Translation System in PHP Website
Quoting Constants in PHP: "This Is a My_Constant"
Type Hinting for Properties in PHP 7