Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

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.

  C# .NET Delegates and Events Simplified

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

  Creating Helper Function in Laravel 6 Example

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.

Leave a Reply

avatar
  Subscribe  
Notify of