In this article, we will see laravel 8 create a custom helper function example. As we all know laravel provides many readymade functions in their framework, but many times we need to require our own customized function to use in our project that time we need to create a custom helper function. So, here we will learn a custom helper function example in laravel 8.
So, let's see the custom helper function in laravel 8.
In this step, we will create an app/helpers.php file in our laravel project and add the below code.
app/helpers.php
<?php
function change_Date_Format($date,$format){
return \Carbon\Carbon::createFromFormat('Y-m-d', $date)->format($format);
}
?>
Add the below code in the composer.json file.
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/helpers.php"
]
},
Now, run the below command in your terminal
composer dump-autoload
So, we are done with the custom helper function in laravel 8, as of now we can use this function anywhere.
Here I am using this function in the blade file.
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Laravel 8 Create Custom Helper Functions Example - websolutionstuff.com</title>
<link rel="stylesheet" href="">
</head>
<body>
<h3>Laravel 8 Create Custom Helper Functions Example - websolutionstuff.com</h3>
<h3>New Date Format: {{ change_Date_Format(date('Y-m-d'),'m/d/Y') }}</h3>
</body>
</html>
Output:
You might also like:
In this article, we will see laravel/framework[v10.0.0, ..., v10.0.3] require composer-runtime-api ^2.2 error fixed...
Mar-07-2023
In this article, we will see laravel whereDate and whereDay examples. As you all know laravel provides many in...
Jan-21-2021
This article will show us how to validate max file size using javascript. Many times we have a requirement to check...
Aug-03-2020
Hey there! I recently needed to upgrade my PHP version from 8.0 to the latest 8.1 on my Ubuntu server. It's a smart...
Nov-03-2023