How to fix Laravel Group by error in Laravel 5.6

Ripon Uddin

6
Am facing Laravel Group By Error. I can solve this by change

'strict' => true, to 'strick'=>false

Here is my sql query :

select `employee_id`, `section_id`, `out_time` from `attendances` where `employee_id` is not null and `out_time` is null group by `section_id`

its working at sql command. When i tried to run with laravel by this code its showing error .
Laravel Controller Code Below :

$attendances = DB::table('attendances')
            ->select('employee_id','section_id','out_time')
            ->where('employee_id', '!=', null)
            ->where('out_time', null)
            ->groupBy('section_id')->get();

After run this code its showing error, error below :

SQLSTATE[42000]: Syntax error or access violation: 1055 'erp.attendances.employee_id' isn't in GROUP BY (SQL: select `employee_id`, `section_id`, `out_time` from `attendances` where `employee_id` is not null and `out_time` is null group by `section_id`)

How to solve this ?

senty

Try getting the values as collection and then grouping the results, i.e use Collection's groupBy() method instead of query builder.

So your queries should be:

$attendances = DB::table('attendances')
        ->select('employee_id','section_id','out_time')
        ->where('employee_id', '!=', null)
        ->where('out_time', null)
        ->get()
        ->groupBy('section_id');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to fix Laravel's routing error with HttpException?

how to fix foreign key error in laravel migration

Laravel: how to fix interface is not instatiable error?

How to fix Route not defined error in view, with Laravel?

How to fix HTTP ERROR 500 cpanel - laravel

How to fix Laravel token mismatch CSRF error

How to fix this gettallheaders.php error in laravel?

How to fix laravel 404 NotFoundHttpException Error?

How do I fix this error installing Laravel?

How to fix Laravel Error 404 in acceptance environment?

how to fix Laravel Error when executing the route

How to fix Laravel HttpKernel\Exception error

How to fix " php artisan migrate" error in Laravel

Laravel Model relation error how to fix it?

How can I fix a Laravel Mix build error in Laravel 7

How to fix Laravel 5 - The connection was reset/No data received - error in whole app?

How to fix error Call to undefined function link_to_route() laravel 5?

How to fix PHP Parse error: syntax error, unexpected '?', on laravel 5.8

How to fix "Trying to get property of non-object" Laravel 5

How to solve a timeout error in Laravel 5

How to solve undefined variable error in Laravel 5

How to know HTTP error status in Laravel 5

How to fix '0 passed and exactly 1 expected' error in laravel

How to fix 'error : SQLSTATE[HY000]' in migration laravel

How to fix Update error for The POST method is not supported for this route in Laravel 7

How can fix this "GET method is not supported for this route" error in Laravel 8?

How to fix this error in console when I create a new laravel project?

How to fix Error: laravel.log could not be opened?

How to fix Error: laravel.log could not be opened Permission denied?