I need Raw PHP to Laravel Query. Below is the code. Please help me.
$csv_file_info = "SELECT COUNT(email_name) as t_email, MIN(create_date) as create_time,
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_status = 'valid' AND user_id = '$user_id') AS 'count_valid',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_status = 'invalid' AND user_id = '$user_id') AS 'count_invalid',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_status = 'catch all' AND user_id = '$user_id') AS 'count_catchall',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_status = 'unknown' AND user_id = '$user_id') AS 'count_unknown',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_status = 'Not Verify' AND user_id = '$user_id') AS 'count_not_verify',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND verification_response = 'syntax error' AND user_id = '$user_id') AS 'count_syntax',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_type = 'Free Account' AND user_id = '$user_id') AS 'count_free',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_type = 'Role Account' AND user_id = '$user_id') AS 'count_role',
(SELECT COUNT(email_name) FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND email_type = 'Disposable Account' AND user_id = '$user_id') AS 'count_disposable'
FROM user_email_list WHERE csv_file_name = '$csv_file_name' AND user_id = '$user_id' ";
$csv_info = $db->select( $csv_file_info );
$csv_result = $csv_info->fetch_assoc();
CodePudding user response:
You can use DB::table(<table>)->select((DB::raw ...
$result = DB::table('user_email_list')->select((DB::raw('user_email_list.*')))->get();
means SELECT * FROM user_email_list