Create Custom helper Functions in Laravel

Today, We want to share with you Create Custom helper Functions in Laravel.In this post we will show you how to use helper function in laravel, hear for Laravel Custom Helper Functions Fil we will give you demo and example for implement.In this post, we will learn about Laravel 5.8 – Custom Helper Facade Class Example from scratch with an example.

Create Custom helper Functions in Laravel

There are the Following The simple About Create Custom helper Functions in Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.8 custom helper functions, so the add custom helpers in laravel 5.8 for this example is following below.

Create a Laravel Helper Functions

app/Libraries/General.php

<?php
namespace App\Libraries;
class General {
// Laravel 5.8 function to fetch simple gravatar Your Profile photo/image from Main Website Like Name is a gravatar.com using email id.
  public static function getGravatarURL($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $resData = array())
  {
    $live_url = 'http://www.gravatar.com/avatar/';
    $live_url .= md5(strtolower(trim($email)));
    $live_url .= "?s=$s&d=$d&r=$r";
    if ($img)
    {
        $live_url = '<img src="' . $live_url . '"';
        foreach ($resData as $key => $val)
            $live_url .= ' ' . $key . '="' . $val . '"';
        $live_url .= ' />';
    }
    return $live_url;
  }
}

Step 2: Add composer.json Files

Include Simple File Path In composer.json to dump data o the autoloader

"autoload": {
    "files": [
        "app/Libraries/General.php" 
    ]
},

Step 3: Composer in Laravel

Run Composer with Following command

Simple Laravel Functions to run this command to dump the autoloader Automatically.

composer dump-autoload

Simple custom helper in Laravel 5.8

Route::get('/', function(){
    $my_profile_img='<img src="'.General::getGravatarURL('[email protected]').'">';
    echo $my_profile_img;   
});

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Create Custom helper Functions in Laravel.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 6 Custom Date Validation Example
  2.   Laravel 7 Create Custom Helper Function Tutorial Example
  3.   Polymorphic One to Many Relationship Example
  4.   PHP Laravel create Custom helper
  5.   Helper classess in laravel 6 Example - PHP
  6.   Get Responsive navbar menu to Automatically close after anchor link clicked
  7.   Most Useful Laravel String Functions(helpers)
  8.   Show country state city dropdown select box using javascript
  9.   Custom Helper Functions in Laravel 6 Example
  10.   paypal payment gateway integration in php