tracker: Undefined index: PragmaRX\Tracker\Vendor\Laravel\Models\Session

after upgrade to laravel 5.7 I received this error

Undefined index: PragmaRX\Tracker\Vendor\Laravel\Models\Session

Undefined index: PragmaRX\Tracker\Vendor\Laravel\Models\Session {"exception":"[object] (ErrorException(code: 0): Undefined index: PragmaRX\\Tracker\\Vendor\\Laravel\\Models\\Session at C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php:241) [stacktrace]#0 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(241): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined index...', 'C:\\\\wamp\\\\www\\\\SPF...', 241, Array)#1 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(167): Illuminate\\Database\\Eloquent\\Model->initializeTraits()#2 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\Models\\Base.php(16): Illuminate\\Database\\Eloquent\\Model->__construct(Array)#3 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\Models\\Session.php(24): PragmaRX\\Tracker\\Vendor\\Laravel\\Models\\Base->__construct(Array)#4 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(417): PragmaRX\\Tracker\\Vendor\\Laravel\\Models\\Session->__construct()#5 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(169): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->instantiateModel('session_model')#6 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(764): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}(Object(Illuminate\\Foundation\\Application), Array)#7 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(646): Illuminate\\Container\\Container->build(Object(Closure))#8 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(601): Illuminate\\Container\\Container->resolve('tracker.reposit...', Array)#9 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(733): Illuminate\\Container\\Container->make('tracker.reposit...', Array)#10 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(1210): Illuminate\\Foundation\\Application->make('tracker.reposit...')#11 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(150): Illuminate\\Container\\Container->offsetGet('tracker.reposit...')#12 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(764): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}(Object(Illuminate\\Foundation\\Application), Array)#13 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(646): Illuminate\\Container\\Container->build(Object(Closure))#14 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(601): Illuminate\\Container\\Container->resolve('tracker', Array)#15 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(733): Illuminate\\Container\\Container->make('tracker', Array)#16 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(1210): Illuminate\\Foundation\\Application->make('tracker')#17 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(635): Illuminate\\Container\\Container->offsetGet('tracker')#18 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(493): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->getTracker()#19 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(357): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}('eloquent.bootin...', Array)#20 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(209): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('eloquent.bootin...', Array)#21 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasEvents.php(162): Illuminate\\Events\\Dispatcher->dispatch('eloquent.bootin...', Array)#22 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(184): Illuminate\\Database\\Eloquent\\Model->fireModelEvent('booting', false)#23 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(165): Illuminate\\Database\\Eloquent\\Model->bootIfNotBooted()#24 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\Models\\Base.php(16): Illuminate\\Database\\Eloquent\\Model->__construct(Array)#25 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\Models\\Session.php(24): PragmaRX\\Tracker\\Vendor\\Laravel\\Models\\Base->__construct(Array)#26 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(417): PragmaRX\\Tracker\\Vendor\\Laravel\\Models\\Session->__construct()#27 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(169): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->instantiateModel('session_model')#28 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(764): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}(Object(Illuminate\\Foundation\\Application), Array)#29 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(646): Illuminate\\Container\\Container->build(Object(Closure))#30 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(601): Illuminate\\Container\\Container->resolve('tracker.reposit...', Array)#31 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(733): Illuminate\\Container\\Container->make('tracker.reposit...', Array)#32 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(1210): Illuminate\\Foundation\\Application->make('tracker.reposit...')#33 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(150): Illuminate\\Container\\Container->offsetGet('tracker.reposit...')#34 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(764): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}(Object(Illuminate\\Foundation\\Application), Array)#35 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(646): Illuminate\\Container\\Container->build(Object(Closure))#36 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(601): Illuminate\\Container\\Container->resolve('tracker', Array)#37 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(733): Illuminate\\Container\\Container->make('tracker', Array)#38 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(1210): Illuminate\\Foundation\\Application->make('tracker')#39 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(635): Illuminate\\Container\\Container->offsetGet('tracker')#40 C:\\wamp\\www\\SPF\\vendor\\pragmarx\\tracker\\src\\Vendor\\Laravel\\ServiceProvider.php(373): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->getTracker()#41 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(360): PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider->PragmaRX\\Tracker\\Vendor\\Laravel\\{closure}(Object(Illuminate\\Routing\\Events\\RouteMatched))#42 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(209): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Rout...', Array)#43 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(653): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Rout...')#44 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(622): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))#45 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(611): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))#46 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))#47 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))#48 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#49 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#50 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#51 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#52 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#53 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#54 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#55 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#56 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#57 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#58 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#59 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#60 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#61 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#62 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#63 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#64 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#65 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#66 C:\\wamp\\www\\SPF\\vendor\enatomarinho\\laravel-page-speed\\src\\Middleware\\PageSpeed.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#67 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): RenatoMarinho\\LaravelPageSpeed\\Middleware\\PageSpeed->handle(Object(Illuminate\\Http\\Request), Object(Closure))#68 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#69 C:\\wamp\\www\\SPF\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#70 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))#71 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#72 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#73 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))#74 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#75 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#76 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))#77 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#78 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#79 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))#80 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#81 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#82 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))#83 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))#84 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))#85 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))#86 C:\\wamp\\www\\SPF\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))#87 C:\\wamp\\www\\SPF\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))#88 {main}"}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I’ve tried disabled parent::__construct($attributes) in https://github.com/antonioribeiro/tracker/blob/master/src/Vendor/Laravel/Models/Base.php#L16, seems to be working, but of course, not the desire solution.

And i’m still look around for the proper solution.

Fixed!

I really didn’t like commenting the parent::__construct() function, it’s probably going to break a lot of things down the line which I don’t want to deal with.

I forked the project so I just did the changes in that repo, you can probably override the Model in your project to get the same result (see above for some instructions). Here’s what I did:

    public function __construct(array $attributes = [])
    {
        // https://github.com/antonioribeiro/tracker/issues/402
        static::$traitInitializers['PragmaRX\Tracker\Vendor\Laravel\Models\Session'] = ['placeholder'];
        parent::__construct($attributes);
    }

    protected function placeholder(){
        // Satisfy the initializer above
    }

This workaround shouldn’t have any side effects. Still don’t solve the issue properly but at least it’s better.

@Wotuu has a good approach here while we wait for the patch. For those new with overriding the model here is what you’d do to get it working with Laravel 5.7:

  1. Create a new model titled : “Session.php”, I placed it in a folder called Tracker like so app\Tracker\Session.php

  2. Extend the Vendor Model and then override the constructor:

<?php

namespace App\Tracker;

use PragmaRX\Tracker\Vendor\Laravel\Models\Session as TrackerSession;

class Session extends TrackerSession{

    /*
     * The PragmaRX\Tracker seems to have an undefined index bug with L5.7.
     * Applying this quick fix : https://github.com/antonioribeiro/tracker/issues/402
     */
    public function __construct(array $attributes = [])
    {
        static::$traitInitializers['App\Tracker\Session'] = ['placeholder'];
        parent::__construct($attributes);
    }

    protected function placeholder(){
        // Satisfy the initializer above
    }
}

Note: The name has to be “Session”, if you name it something else like Tracker_Session - a core sql query will fail. In this example ‘Tracker_Session’ would result in this sql query to be executed:

select * from `tracker_log` where `tracker_log`.`tracker__session_id`

So the model name is what is used in the query. Keep that in mind.

  1. Go to App\config\tracker.php and update array for ‘session_model’. In my case I changed:
'session_model' => 'PragmaRX\Tracker\Vendor\Laravel\Models\Session',

to:

'session_model' => 'App\Tracker\Session',

Enable the tracker, if you’re testing it on your localhost, empty the 'do_not_track_ips' array to exclude it. It should work then. 👍

Any Progress On This?.

bonus for Stats Controller

`<?php

namespace Modules\Administrator\Http\Controllers\Admin;

use Yajra\DataTables\Facades\DataTables; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\View; use PragmaRX\Tracker\Vendor\Laravel\Facade as Tracker; use PragmaRX\Tracker\Vendor\Laravel\Support\Session;

class Stats extends AdminController { private $adminProperties = [ ‘admin’, ‘root’, ‘is_admin’, ‘is_root’, ];

public function __construct()
{
    $this->authentication = app()->make('tracker.authentication');
    $template_path = url('/').$this->getConfig('stats_template_path');
    View::share('stats_template_path', $template_path);
}

/**
 * Get a configuration value
 *
 * @param  string $key
 * @return mixed
 */
public function getConfig($key = null)
{

    $key = "tracker" . ($key ? '.'.$key : '');

    return app()->config->get($key);
}

public function index(Session $session)
{
    if (!$this->isAuthenticated()) {
        return View::make('pragmarx/tracker::message')->with('message', _t('administrator.tracker.auth_required'));
    }

    if (!$this->hasAdminProperty()) {
        return View::make('pragmarx/tracker::message')->with('message', _t('administrator.tracker.miss_admin_prop'));
    }

    if (!$this->isAdmin()) {
        return View::make('pragmarx/tracker::message')->with('message', _t('administrator.tracker.not_admin'));
    }

    return $this->showPage($session, $session->getValue('page'));
}

/**
 * @param Session $session
 */
public function showPage($session, $page)
{
    $me = $this;

    if (method_exists($me, $page)) {
        return $this->$page($session);
    }
}

public function visits(Session $session)
{
    $datatables_data =
    [
        'datatables_ajax_route' => route('tracker.stats.api.visits'),
        'datatables_columns'    => '
            { "data" : "id",          "title" : "'._t('administrator.tracker.id').'", "orderable": true, "searchable": true },
            { "data" : "client_ip",   "title" : "'._t('administrator.tracker.ip_address').'", "orderable": true, "searchable": true },
            { "data" : "country",     "title" : "'._t('administrator.tracker.country_city').'", "orderable": true, "searchable": true },
            { "data" : "user",        "title" : "'._t('administrator.tracker.user').'", "orderable": true, "searchable": true },
            { "data" : "device",      "title" : "'._t('administrator.tracker.device').'", "orderable": true, "searchable": true },
            { "data" : "browser",     "title" : "'._t('administrator.tracker.browser').'", "orderable": true, "searchable": true },
            { "data" : "language",    "title" : "'._t('administrator.tracker.language').'", "orderable": true, "searchable": true },
            { "data" : "referer",     "title" : "'._t('administrator.tracker.referer').'", "orderable": true, "searchable": true },
            { "data" : "pageViews",   "title" : "'._t('administrator.tracker.page_views').'", "orderable": true, "searchable": true },
            { "data" : "lastActivity","title" : "'._t('administrator.tracker.last_activity').'", "orderable": true, "searchable": true },
        ',
    ];

    return $this->view('administrator.tracking.index')
        ->with('sessions', Tracker::sessions($session->getMinutes()))
        ->with('title', ''._t('administrator.tracker.visits').'')
        ->with('username_column', Tracker::getConfig('authenticated_user_username_column'))
        ->with('datatables_data', $datatables_data);
}

public function log($uuid)
{
    $session = Tracker::sessionLog($uuid);

    return View::make('pragmarx/tracker::log')
            ->with('log', Tracker::sessionLog($uuid))
            ->with('uuid', $uuid)
            ->with('title', 'log');
}

public function summary()
{
    return $this->view('administrator.tracking.summary2')
    //return View::make('pragmarx/tracker::summary')
            ->with('title', ''._t('administrator.tracker.page_views_summary').'');
}

public function apiPageviews(Session $session)
{
    return Tracker::pageViews($session->getMinutes())->toJson();
}

public function apiPageviewsByCountry(Session $session)
{
    return Tracker::pageViewsByCountry($session->getMinutes())->toJson();
}

public function apiLog($uuid)
{
    $query = Tracker::sessionLog($uuid, false);

    $query->select([
                        'id',
                        'session_id',
                        'method',
                        'path_id',
                        'query_id',
                        'route_path_id',
                        'is_ajax',
                        'is_secure',
                        'is_json',
                        'wants_json',
                        'error_id',
                        'created_at',
                    ]);

    return \Yajra\DataTables\Facades\DataTables::of($query)
        ->editColumn('route_name', function ($row) {
            $path = $row->routePath;

            return    $row->routePath
                        ? $row->routePath->route->name.'<br>'.$row->routePath->route->action
                        : ($row->path ? $row->path->path : '');
        })

        ->editColumn('route', function ($row) {
            $route = null;

            if ($row->routePath) {
                foreach ($row->routePath->parameters as $parameter) {
                    $route .= ($route ? '<br>' : '').$parameter->parameter.'='.$parameter->value;
                }
            }

            return $route;
        })

        ->editColumn('query', function ($row) {
            $query = null;

            if ($row->logQuery) {
                foreach ($row->logQuery->arguments as $argument) {
                    $query .= ($query ? '<br>' : '').$argument->argument.'='.$argument->value;
                }
            }

            return $query;
        })

        ->editColumn('is_ajax', function ($row) {
            return    $row->is_ajax ? 'yes' : 'no';
        })

        ->editColumn('is_secure', function ($row) {
            return    $row->is_secure ? 'yes' : 'no';
        })

        ->editColumn('is_json', function ($row) {
            return    $row->is_json ? 'yes' : 'no';
        })

        ->editColumn('wants_json', function ($row) {
            return    $row->wants_json ? 'yes' : 'no';
        })

        ->editColumn('error', function ($row) {
            return    $row->error ? 'yes' : 'no';
        })

        ->make(true);
}

public function users(Session $session)
{
    return $this->view('administrator.tracking.users')
        ->with('users', Tracker::users($session->getMinutes()))
        ->with('title', ''._t('administrator.tracker.users').'')
        ->with('username_column', Tracker::getConfig('authenticated_user_username_column'));
}

private function events(Session $session)
{
    return $this->view('administrator.tracking.events')
        ->with('events', Tracker::events($session->getMinutes()))
        ->with('title', ''._t('administrator.tracker.events').'');
}

public function errors(Session $session)
{
    return $this->view('administrator.tracking.errors')
        ->with('error_log', Tracker::errors($session->getMinutes()))
        ->with('title', ''._t('administrator.tracker.errors').'');
}

public function apiErrors(Session $session)
{
    $query = Tracker::errors($session->getMinutes(), false);

    $query->select([
                        'id',
                        'error_id',
                        'session_id',
                        'path_id',
                        'updated_at',
                    ]);

    return \Yajra\DataTables\Facades\DataTables::of($query)
            ->editColumn('updated_at', function ($row) {
                return "{$row->updated_at->diffForHumans()}";
            })
            ->make(true);
}

public function apiEvents(Session $session)
{
    $query = Tracker::events($session->getMinutes(), false);

    return \Yajra\DataTables\Facades\DataTables::of($query)->make(true);
}

public function apiUsers(Session $session)
{
    $username_column = Tracker::getConfig('authenticated_user_username_column');

    return \Yajra\DataTables\Facades\DataTables::of(Tracker::users($session->getMinutes(), false))
            ->editColumn('user_id', function ($row) use ($username_column) {
                return "{$row->user->$username_column}";
            })
            ->editColumn('updated_at', function ($row) {
                return "{$row->updated_at->diffForHumans()}";
            })
            ->make(true);
}

public function apiVisits(Session $session)
{
    $username_column = Tracker::getConfig('authenticated_user_username_column');

    $query = Tracker::sessions($session->getMinutes(), false);

    $query->select([
            'id',
            'uuid',
            'user_id',
            'device_id',
            'agent_id',
            'client_ip',
            'referer_id',
            'cookie_id',
            'geoip_id',
            'language_id',
            'is_robot',
            'updated_at',
    ]);

    return \Yajra\DataTables\Facades\DataTables::of($query)
            ->editColumn('id', function ($row) use ($username_column) {
                $uri = route('tracker.stats.log', $row->uuid);

                return '<a href="'.$uri.'">'.$row->id.'</a>';
            })

            ->addColumn('country', function ($row) {
                $cityName = $row->geoip && $row->geoip->city ? ' - '.$row->geoip->city : '';

                $countryName = ($row->geoip ? $row->geoip->country_name : '').$cityName;

                $countryCode = strtolower($row->geoip ? $row->geoip->country_code : '');

                $flag = $countryCode
                        ? "<span class=\"f16\"><span class=\"flag $countryCode\" alt=\"$countryName\" /></span></span>"
                        : '';

                return "$flag $countryName";
            })

            ->addColumn('user', function ($row) use ($username_column) {
                return $row->user ? $row->user->$username_column : 'guest';
            })

            ->addColumn('device', function ($row) use ($username_column) {
                $model = ($row->device && $row->device->model && $row->device->model !== 'unavailable' ? '['.$row->device->model.']' : '');

                $platform = ($row->device && $row->device->platform ? ' ['.trim($row->device->platform.' '.$row->device->platform_version).']' : '');

                $mobile = ($row->device && $row->device->is_mobile ? ' [mobile device]' : '');

                return $model || $platform || $mobile
                        ? $row->device->kind.' '.$model.' '.$platform.' '.$mobile
                        : '';
            })

            ->addColumn('browser', function ($row) use ($username_column) {
                return $row->agent && $row->agent
                        ? $row->agent->browser.' ('.$row->agent->browser_version.')'
                        : '';
            })

            ->addColumn('language', function ($row) use ($username_column) {
                return $row->language && $row->language
                    ? $row->language->preference
                    : '';
            })

            ->addColumn('referer', function ($row) use ($username_column) {
                return $row->referer ? $row->referer->domain->name : '';
            })

            ->addColumn('pageViews', function ($row) use ($username_column) {
                return $row->page_views;
            })

            ->addColumn('lastActivity', function ($row) use ($username_column) {
                return $row->updated_at->diffForHumans();
            })

            ->rawColumns(['id', 'country'])

            ->make(true);
}

private function isAuthenticated()
{
    return $this->authentication->check();
}

private function hasAdminProperty()
{
    $user = $this->authentication->user();

    foreach ($this->adminProperties as $property) {
        $propertyCamel = camel_case($property);

        if (
                isset($user->$property) ||
                isset($user->$propertyCamel) ||
                method_exists($user, $property) ||
                method_exists($user, $propertyCamel)
        ) {
            return true;
        }
    }

    return false;
}

private function isAdmin()
{
    $user = $this->authentication->user();

    foreach ($this->adminProperties as $property) {
        $propertyCamel = camel_case($property);

        if (
            (isset($user->$property) && $user->$property) ||
            (isset($user->$propertyCamel) && $user->$propertyCamel) ||
            (method_exists($user, $property) && $user->$property()) ||
            (method_exists($user, $propertyCamel) && $user->$propertyCamel())
        ) {
            return true;
        }
    }

    return false;
}

}

`

And config: ‘stats_controllers_namespace’ => ‘Modules\Administrator\Http\Controllers\Admin’,

sorry, i used Module, please change Modules\Administrator\Http\Controllers\Admin to App\Http\Controllers\Admin

and copy all files view form vender to your APP