Custom helper in Laravel 5
In laravel project some functions and some repeating code, so at that time you have to create some helper functions that can help to clear way and you do not need to write more code, save time and very flexible, that way you can easily modify that code.
Step 1: Create helpers.php
File
To create app/Http/helpers.php
in your laravel project and put the following code in that file:
function changeDateFormate($date,$date_format){
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format($date_format);
}
function productImagePath($image_name)
{
return public_path('images/products/'.$image_name);
}
Step 2: Add File Path In composer.json
File
You have to put the path of helpers file, so basically open composer.json file and put following code in that file:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Http/helpers.php" //Add This Line
]
},
Step 3: Run Command
You should run the following command:
composer dump-autoload
you can use your custom helper functions like changeDateFormate()
and productImagePath()
.
hodoto 9453
03 Feb 2022
ggg
robertfc rocker
28 Feb 2022
i really like this article please keep it up. augusta precious metals ratings
robertfc rocker
28 Feb 2022
I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information. a pet project for Doug Haynes
parer 45632
17 May 2022
Great content material and great layout. Your website deserves all of the positive feedback it’s been getting. diigo
parer 45632
28 May 2022
Excellent website you have here, so much cool information!.. chatrad
hodoto 9453
16 Jun 2022
This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. Hyll on Holland Price
Albina
10 Sep 2022
Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks pierogi
Albina
10 Sep 2022
Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. crypto jobs
Albina
10 Sep 2022
Cooling dog beds are great for relief on hot days — but how do you find the right one? The puncture-resistant cooling mat for dog bed will work to regulate your dog’s body temperature, either by being elevated off the floor to allow for airflow or made with materials like cooling gel or copper to trap heat and move it away from your pup.