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

Laravel Create Custom Helper Class Example

Today, We want to share with you Laravel Create Custom Helper Class Example.In this post we will show you Creating a Helpers file in a Laravel App, hear for Creating your own PHP helper functions in Laravel we will give you demo and example for implement.In this post, we will learn about How To Create A Custom Helper Class In Laravel MVC with an example.

Laravel Create Custom Helper Class Example

There are the Following The simple About Laravel Create Custom Helper Class Example Full Information With Example and source code.

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

  Dynamic QR codes Generator in Laravel 5.7

Step : 1 Create Laravel helpers.php file

app/helpers.php

<?php

function getMemberProfile($id) {
    $data = \DB::table('users')
        ->select(\DB::raw('CONCAT(firstname, " ", lastname) as username'))
        ->where('id', $id)
        ->first();

    return $data->username;
}

Step : 2 Add app/helpers.php file in composer.json file

app/helpers.php

"autoload": {
    "classmap": [
        ...
    ],

    "psr-4": {
        "App\": "app/"
    },

    "files": [
        "app/helpers.php" //Add This Line
    ]
},

After done this then once we are run following command.

composer dump-autoload

Step : 3 Use Custom Laravel Helper In Controller

Create a Laravel Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;

class HomeController extends Controller
{   
    
    public function index()
    {
        $fullprofiledetails = getMemberProfile(Auth::user()->id);
        dd($fullprofiledetails);
    }

}

Step : 4 Use Custom Laravel Helper In Blade File

Laravel Blade View Files

@extends('layouts.app')

@section('content')

<?php
    $fullprofiledetails = getMemberProfile(Auth::user()->id);
    dd($fullprofiledetails);
?>

@endsection

Angular 6 CRUD Operations Application Tutorials

Read :

Create A Custom Helper Class In Laravel MVC

  Simple Vuejs Currency Converter Example

Summary

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

I hope you get an idea about Laravel Create Custom Helper Class Example.
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.