How to Create Laravel Helper With Example
This tutorial is for How to Create Laravel Helper With Example. Laravel build-in provides helper functions that can call anywhere within your application. Laravel are many helper functions defined, and you can define your project’s own helper functions.
The helper is the main use of your site URL load before its function call. other language helper functions use for helper file calls but Laravel in composer.json is defined.
Simple your project directory in the app folder or app\helpers folder to create a helper. here is only the app/ folder in creating the helpers.php file
step 1: Create helper file
app\helpers.php
step 2: open the helper.php file and add this function.
#app\helpers.php if(!function_exists('get_options')) { function get_options() { return "Helper function load!"; } }
step 3: composer.json file changes
#composer.json "autoload": { "files": [ "app/helpers.php" #added ], //added "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" } },
step 4: Open the command prompt and run the below command :
composer dump-autoload
step 5: You can use the helper function in the blade file or controller file
#index.blade.php {{ get_options() }}
#HomeController.php $messages = get_options();