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条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?