Laravel 5/6/7 create custom facade

Today, We want to share with you Laravel 5/6/7 create custom facade.In this post we will show you laravel set facade root, hear for lumen custom facade we will give you demo and example for implement.In this post, we will learn about create custom service provider in laravel with an example.

Laravel 5/6/7 create custom facade

There are the Following The simple About laravel date facade Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel real-time facades, so the create facade laravel 6 is used for this example is following below.

Laravel is a web application framework with expressive, elegant syntax.The PHP Framework for Web Artisans,freeing you to create without sweating the small things. CRUD Operation With Server Side.

Read Also:  Send email via Gmail SMTP server in Laravel 7/6

Keywords : laravel create facade,laravel 5 create facade example,laravel 5.2 create custom facade,laravel create custom facade tutorial,How to create facade in laravel 5.2

Phase 1:Make a class file app/ItSolution/BdayWishClass.php

app/ItSolution/BdayWishClass.php

namespace App\ItSolution;
class BdayWishClass {
    public function productImagePath($image_name)
    {
        return public_path('images/products/'.$image_name);
    }
    public function converCustomFormatTimezone($date,$date_format){
		return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)
					->format($date_format);
	}
}

Phase 2:Make a ServiceProvider

php artisan make:provider 'BdayWishClassServiceProvider'

app/Providers/BdayWishClassServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App;
class BdayWishClassServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
         App::bind('bdaywishclass', function()
        {
            return new \App\ItSolution\BdayWishClass;
        });
    }
}

Phase 3:Make a Facade Class

app/ItSolution/BdayWishClassFacade.php

namespace App\ItSolution;
use Illuminate\Support\Facades\Facade;
class BdayWishClassFacade extends Facade{
    protected static function getFacadeAccessor() { return 'bdaywishclass'; }
}

Phase 4:Register Service Provider

Config\app.php

// In providers array
App\Providers\BdayWishClassServiceProvider::class,

// In aliases array
'BdayWishClass'=> App\ItSolution\BdayWishClassFacade::class

Phase 5:composer dump

This is the last step and you have to do just composer dump-autoload in your terminal:

Read Also:  Create array in laravel 5

composer dump-autoload

Route::get('bdaywishclass', function(){
    $imagepath = BdayWishClass::productImagePath('image.jpg');

    dump($imagepath);

});

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about facades in laravel.
I would like to have feedback on my infinityknow.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.