Last active
August 29, 2015 14:27
-
-
Save petersuhm/6d6768a402f6507e9dd5 to your computer and use it in GitHub Desktop.
Bind a class to current authenticated object in a multi tenant app.
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 | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// Bind Account to the account of the current authenticated user | |
$this->app->bind(Account::class, function(Application $app) { | |
$user = $app['auth']->user(); | |
return $user->getAccount(); | |
}); | |
} | |
} | |
// In some controller | |
public function store(Account $account) | |
{ | |
// $account will be account of the current authenticated user. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment