This is LARA Nepal. X

Laravel: How To Implement Hamropatro Api For Nepali Date Conversion

Published on March 1, 2024 by

Laravel: How to Implement HamroPatro API for Nepali Date Conversion

HamroPatro API for Nepali Date Conversion

Hey Laravel enthusiasts! Are you working on a project that requires converting English dates to Nepali dates? Look no further, as I'm here to guide you through implementing the HamroPatro API for seamless Nepali date conversions in your Laravel application.

Write the Conversion Function

let's add the function englishDateToNepaliDate() in your helper.php file. This function will make a POST request to the HamroPatro API to convert English dates to Nepali dates.

use Illuminate\Support\Facades\Http;
 
if (!function_exists('englishDateToNepaliDate')) {
function englishDateToNepaliDate()
{
$response = Http::asForm()
->post('https://www.hamropatro.com/getMethod.php', [
'actionName' => 'wdconverter',
'datefield' => date('Y-m-d'),
'convert_option' => 'eng_to_nep',
]);
 
if ($response->failed()) {
return false;
}
 
return $response->body();
}
}

You can now utilize this helper function wherever you need to convert English dates to Nepali dates in your Laravel application. Simply call englishDateToNepaliDate() to retrieve the converted date.

<li>
<i class="far fa-clock"></i>
{!!englishDateToNepaliDate()!!}
</li>

it will look like this: That's it! You've successfully implemented the HamroPatro API for Nepali date conversion in your Laravel application. Feel free to customize the helper function further to suit your specific requirements.

Discussion

Login or register to comment or ask questions

No comments or questions yet...