How to create service provider in laravel

Laravel is the most used php framework in these days.its very easy to custmize and use.laravel have wide range of in this blog i will tech you how to create a service provider in laravel (5.*).so lest start :

1) First step is we neend to create a file in App folder:
i create a folder name PS and create a file in this folder name PS.php written the bellow code:

namespace App\PS;

use DB;

class LB {

//create a function

public static function helloPunit()


    return "Hello i am punit";



this is main file where we will create function according to our requirment.

2) Second step is now we will register this service provider:
create a file in provider folder (located in App folder) for example i will create PSServiceProvider.php write the bellow code in it:

namespace app\Providers;


use Illuminate\Support\ServiceProvider;

class PSServiceProvider extends ServiceProvider {

/*Bootstrap the application services.*/

public function boot()

{ // }

/*Register the application services. */

public function register()


foreach (glob(app_path().'/PS/*.php') as $filename)






3) 3rdstep is we will config the app file (App.php in config folder)

add this line in providers array:

add this line in Aliases array:
'LB' => App\PS\PS::class,

Thats it we ready to use this service provider in our controller include this class like use PS

when we will call this

function PS::helloPunit();

it will return "Hello i am punit" I hope you enjoy this post and we will try to provide you even more usefull stuff.Keep visiting our blog.