Last active
December 19, 2015 16:59
-
-
Save nazieb/5988113 to your computer and use it in GitHub Desktop.
Facebook Facade in Laravel 4. Using Facade & Service Provider you can create a global "FB" class which you can call statically in Controllers / Routes / Views. For the example:
<?php echo FB::getLoginUrl();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // app/config/app.php | |
| 'providers' => array( | |
| 'Illuminate\Foundation\Providers\ArtisanServiceProvider', | |
| // ..... | |
| 'App\DependenciesProvider', | |
| ), | |
| // ..... | |
| 'aliases' => array( | |
| 'App' => 'Illuminate\Support\Facades\App', | |
| // ..... | |
| 'FB' => 'App\FacebookFacade', | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "require": { | |
| "laravel/framework": "4.0.*", | |
| "facebook/php-sdk": "dev-master" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace Facebook; | |
| // app/libs/facebook/FacebookFacade.php | |
| use Illuminate\Support\Facades\Facade; | |
| class FacebookFacade extends Facade { | |
| protected static function getFacadeAccessor() { return 'facebook'; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace Facebook; | |
| // app/libs/facebook/FacebookProvider.php | |
| use Illuminate\Support\ServiceProvider; | |
| class FacebookProvider extends ServiceProvider { | |
| /** | |
| * Register application dependencies | |
| * | |
| */ | |
| function register() | |
| { | |
| $this->app->singleton('facebook', function(){ | |
| return new \Facebook(array( | |
| 'appId' => \Config::get('fb.app_id'), | |
| 'secret' => \Config::get('fb.secret'), | |
| )); | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // app/config/fb.php | |
| return array( | |
| 'app_id' => '-- app ID --', | |
| 'secret' => '-- Secret --' | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment