How To Create Facade On Laravel 5.1
Posted on 9 months ago
Here is step by step to create facade on laravel 5.1
Create PHP Class File.
Bind that class to Service Provider
Register that ServiceProvider to Config\app.php as providers
Create Class which is this class extends to Illuminate\Support\Facades\Facade
Register point 4 to Config\app.php as aliases
Step 1 - Create PHP Class File, for example in App\Classes\Someclass.php
<?php
/*
* Created by PhpStorm.
* User: n0impossible
* Date: 6/13/15
* Time: 11:35 AM /
namespace App\Classes;
class Someclass {
public function get($data = [])
{
echo "foo";
}
}
Step 2 - Bind that class to Service Provider
In case i create a new serviceprovider by execute
php artisan make:provider 'SomeclassServiceProvider'
then add
Step 4 - Create Class which is this class extends to Illuminate\Support\Facades\Facade
For Example I create this class in App\Facades\Someclass.php
<?php
/*
* Created by PhpStorm.
* User: n0impossible
* Date: 6/14/15
* Time: 1:47 PM /
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Someclas extends Facade{
protected static function getFacadeAccessor() { return 'someclass'; }
}
Step 5 - Register point 4 to Config\app.php as aliases
How To Create Facade On Laravel 5.1
Posted on 9 months ago
Here is step by step to create facade on laravel 5.1
Create PHP Class File.
Bind that class to Service Provider
Register that ServiceProvider to Config\app.php as providers
Create Class which is this class extends to Illuminate\Support\Facades\Facade
Register point 4 to Config\app.php as aliases
Step 1 - Create PHP Class File, for example in App\Classes\Someclass.php
<?php
/*
* Created by PhpStorm.
* User: n0impossible
* Date: 6/13/15
* Time: 11:35 AM
/
namespace App\Classes;
class Someclass {
public function get($data = [])
{
echo "foo";
}
}
Step 2 - Bind that class to Service Provider
In case i create a new serviceprovider by execute
php artisan make:provider 'SomeclassServiceProvider'
then add
Like so
<?php
namespace App\Providers;
use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
class SomeclassServiceProvider extends ServiceProvider
{
/*
* Bootstrap the application services.
*
* @return void
/
public function boot()
{
//
}
}
Step 3 - Register that ServiceProvider to Config\app.php as providers
Step 4 - Create Class which is this class extends to Illuminate\Support\Facades\Facade
For Example I create this class in App\Facades\Someclass.php
<?php
/*
* Created by PhpStorm.
* User: n0impossible
* Date: 6/14/15
* Time: 1:47 PM
/
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Someclas extends Facade{
protected static function getFacadeAccessor() { return 'someclass'; }
}
Step 5 - Register point 4 to Config\app.php as aliases
'Someclass' => App\Facades\Someclass::class
Testing
On App\Http\routes.php create single route
Route::get('/', function(){
Someclass::get();
});
Then check on your browser