Create Custom Helper in Laravel
Cutsom helper is used to call a function in multiple file at a time.It Is very simpe and easy method to call a function in your web appllication.
Use Below Code :
Step 1 : Create a folder Helpers in app directory.
Step 2 : Then Create a helper file like CustomHelper.php in Helpers folder.
Step 3 : after this copy below code and paste that in your file
namespace App\Helpers;
class CustomHelper {
public static function YourFunctionName()
{
echo “hello world”;
}
}
Step 4 : then open your app/config.php file use below code.
‘aliases’ => [
.
CustomHelper’ => App\Helpers\CustomHelper::class
],
Step 5 : after all this use below code in your controller.
\CustomHelper::YourFunctionName();