Skip to content

Instantly share code, notes, and snippets.

@petersuhm
Last active August 29, 2015 14:27
Show Gist options
  • Save petersuhm/6d6768a402f6507e9dd5 to your computer and use it in GitHub Desktop.
Save petersuhm/6d6768a402f6507e9dd5 to your computer and use it in GitHub Desktop.
Bind a class to current authenticated object in a multi tenant app.
<?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