2017-10-17 08:29


Suppose I have the following class:

class MyClass {

    private $someVar;

    public function __construct($someParameter) {
        $this->someVar = $someParameter;

    public function display(){
        return "This is the variable value " . $this->someVar;


How am I suppose to bind this class to the container as I need to pass the variable to the constructor as well?

Normally, I would get an instance of the class and pass the variable. Like;

$param = 'this is my variable.';
$obj = new MyClass($param);
echo $obj->display();

I need to do this through the service provider.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答