dqudtskm49788 2016-08-11 01:33
浏览 141
已采纳

如何访问Tracker(antonioribeiro / tracker)对象在Laravel中

I am using AntonioRiveiro/Tracker repo for my laravel app. I would like to add some more functionality to it that it doesn't have out of the box.

  1. But I can't find where its instance gets created, or how to access the Tracker object in my Controllers.

  2. Or how do I extend the tracker object?

  • 写回答

2条回答 默认 最新

  • douan6815 2016-08-11 02:02
    关注

    So I think the easiest way for you to go about this is the following:

    First, make your own ServiceProvider

    php artisan make:provider CustomTrackerServiceProvider
    

    Now open up that file, we'll need to make some modifications.

    Firstly, we'll need to extend the ServiceProvider that Tracker provides.

    use PragmaRX\Tracker\Vendor\Laravel\ServiceProvider as TrackerServiceProvider
    
    class CustomTrackerServiceProvider extends TrackerServiceProvider
    

    The use alias above is not required, but I prefer it for clarity given the similar naming convention to the core framework.

    Now you'll need to replace your usage of the PragmaRX\Tracker\Vendor\Laravel\ServiceProvider in your config/app.php file under the providers array

    config/app.php
    'providers' => [
        //other providers and what have you
        App\Http\Providers\CustomTrackerServiceProvider::class
    ]
    

    Now you have the ability to make changes. You can override the default functionality of the core class as long as it's member is not private.

    Have a look at the vendor provided file and identify a similar architecture pattern to the vendor maintainer, and you'll be good to go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!