Problem : Max can not return max value from varchar type field.
Problem : Max can not return max value from varchar type field.
ELOQUENT Query : $maxLicence = Agency::where('is_approved',1)->max('license_no');
RAW SQL Query : select max(test_value) from area_info;
Solution :
$maxLicence = DB::select("select max(cast(agencys.license_no as int)) as license from agencys");
ELOQUENT Query : $maxLicence = Agency::where('is_approved',1)->max('license_no');
RAW SQL Query : select max(test_value) from area_info;
Solution :
$maxLicence = DB::select("select max(cast(agencys.license_no as int)) as license from agencys");
Comments
Post a Comment