jeudi 29 novembre 2018

Laravel service container bing class constructor with parameter

I have a Closet class, its constructor with 3 parameter.

Class Closet
{
    public function __construct($size, $length, Jeans $Jeans)
    {
        $this->size = $size;
        $this->length = $length;
        $this->Jeans = $Jeans;
    }
}

And I need to use dependency injection on some where.

Class Outfit
{
    public function __construct(Closet $Closet)
    {
        $this->Closet = $Closet;
    }

    public function pants($size, $length)
    {
        $this->Closet($size, $length);
    }
}

so I bind it in Provider

public function register()
{

    $this->app->singleton(Closet::class, function ($app) {
        return new Closet($app->make('Jeans'));
    });

}

What should I do to bind $size, $length into register?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PazDVw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire