Laravel Provider a lot of helper functions for Arrays & Objects, Strings, Fluent Strings, Miscellaneous, and the most used helper function dd().
Step 1: Define Your Helper Functions
To define helpers in laravel create a php file and define a class with methods in itand place the file at app/helpers.php folder in your laravel application.For example
Step 2: Autoload Your Helpers File
of any custom helper in composer.json.
"autoload": {
"files": [ "app/helpers.php" ],"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
Step 3: Use Your Custom Helper Functions
After adding up the helper file in composer.json we need to the following commandcomposer dump-autoload
And afterword we need to use the newly create custom heper in our laravel.For example
use App\Helpers\CustomHelper;
echo CustomHelper::formatDateTime(now());
No comments:
Post a Comment