Laravel 4: Passing data from make to the service provider

后端 未结 2 437
梦如初夏
梦如初夏 2020-12-18 03:44

The code below says it all...

// routes.php
App::make(\'SimpleGeo\',array(\'test\')); <- passing array(\'test\')

// SimpleGeoServiceProvider.php
pu         


        
2条回答
  •  感动是毒
    2020-12-18 04:11

    You need to pass your test array to the class inside of the service provider

    // NOT in routes.php but when u need it like the controller
    App::make('SimpleGeo'); // <- and don't pass array('test')
    
    public function register()
    {
        $this->app['SimpleGeo'] = $this->app->share(function($app)
        {
            return new SimpleGeo(array('test'));
        });
    }
    

    YourController.php

    Public Class YourController
    {
        public function __construct()
        {
            $this->simpleGeo = App::make('SimpleGeo');
        }
    }
    

提交回复
热议问题