Laravel 4: Confused about how to use App::make()

后端 未结 2 1549
借酒劲吻你
借酒劲吻你 2021-02-06 05:39

I am trying to follow the repository pattern outlined in this article http://code.tutsplus.com/tutorials/the-repository-design-pattern--net-35804#highlighter_174798 And I am try

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 06:13

    The good people in the Laravel forum answered this one for me http://laravel.io/forum/02-10-2014-laravel-4-confused-about-how-to-use-appmake

    Pretty much if you can bind custom instantiation code with App::bind(); like so

    App::bind('My\NewClass', function() use ($classArgs) {
        return new My\NewClass($classArgs['id'], $classArgs['title']);
    });
    
    // get the binding
    $newClass = App::make('My\NewClass');
    

提交回复
热议问题