0

Laravel クエリ:

$studentsFee = \FeeModal::query();
$studentsFee->groupBy('main_campus_id', 'session_id', 'class_info_id', 'section_id', 'stage_id')
                ->selectRaw('count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount')
                ->with('sessionMode', 'section',  'classInfo', 'stage')->get();

dd(count($studentsFee). ' Records' );

結果: 0 レコード

によって生成されたクエリ->toSql();

string(281) "select count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount from `fee` group by `main_campus_id`, `session_id`, `class_info_id`, `section_id`, `stage_id`" 

mysqlでこのクエリを実行すると、18行が返されます。

4

1 に答える 1

0

クエリの結果を変数に代入するのを忘れたと思います:

$studentsQuery = \FeeModal::query();
$studentsFee = $studentsQuery->groupBy('main_campus_id', 'session_id', 'class_info_id', 'section_id', 'stage_id')
                ->selectRaw('count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount')
                ->with('sessionMode', 'section',  'classInfo', 'stage')->get();

dd(count($studentsFee). ' Records' );
于 2016-03-20T00:15:50.253 に答える