I have a Facade Player where i set up a function info, this function will give me the information of the players, the my issue is when i call that function by dependency injection it throw me the error:
Call to undefined method Team\Player\Facades\Player::info()
instead if i call that function doing Player::info();
it Work! Why with the depency throw me that error?
following my class Player
class Player {
use Team\Player\Models\User;
use Team\Player\Models\Team;
use Team\Player\Models\Fighter;
public function info($user_id)
{
return Fighter::with('team','user')->where('player_id','=',$user_id)->first();
}
}
My controller where i try to call the dependecy
class MatchController extends BaseController {
protected $match;
protected $player;
function __construct(Match $match,Player $player) { // dependency injection
$this->match = $match;
$this->player = $player;
}
public function getInfoPlayer()
{
$player_id = Input::get('user_id');
$player = $this->player->info($player_id);
return View::make('site/team/event/scripts/infoPlayer')->withPlayer($player);
}
}
and my service provider where i bind my class
public function register()
{
$this->app['player'] = $this->app->share(function($app)
{
return new Player;
});
$this->app->booting(function()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Player', 'Team\Player\Facades\Player');
});
}