Open joashp opened 6 years ago
Hard to tell without clues.
Do you have any error in your logfile?
Which laravel version are you using?
Can you post your app/Http/Kernel.php and your config/visits.php?
No error logs. Laravel v5.4
Kernel.php file
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, 'Foothing\Laravel\Visits\Middlewares\CountPageView', ];
the config/visits.php file `<?php return [
// Enable or disable tracking.
"enabled" => true,
// Add patterns to be blacklisted (ignored and not tracked).
// These patterns will apply if the UrlWhitelist rule is
// enabled in the chain.
"blacklist" => [
// i.e. '/^(admin|api|auth).*/'
],
// Rules chain.
"rules" => [
"Foothing\Laravel\Visits\Rules\Crawler",
"Foothing\Laravel\Visits\Rules\UrlWhitelist",
],
"cache" => true,
];`
Also, which version of this library are you using?
The latest v1.0.0 stable
Could point me to the files where I add log statements and find out where it is failing?
I'm looking into this but really i can't get any clue.
Try log something in:
Also make sure your database connection is properly configured and working, i.e. you are able to insert records in any of your tables.
Okay. I added logs in both files.
I was able to get the log from CountPageView handle But, it did not get any logs from Visits track
And yes, my database connection is proper, I have other records already with CRUD operations.
Okay,
public function track(Request $request) { Log::info('Visits track before'); if (! $this->trackable($request)) { return false; } Log::info('Visits track');
I get "Visits track before", but not "Visits track"
That is weird, because the only thing middleware does it's invoking Visits::track(). Can you put a log in the very first line of the track method, and another just after the first if block? Might be that for some reason your request is not trackable()
If it's not, you might add some log in the trackable() method aswell.
It's failing here, I get
[2018-02-16 09:15:45] local.INFO: Visits trackable
[2018-02-16 09:15:45] local.INFO: Visits trackable
public function trackable(Request $request) {
Log::info('Visits trackable');
if (! Config::get('visits.enabled')) {
Log::info('Visits trackable'. Config::get('visits.enabled'));
return false;
}
Can you please add this log in the first line of trackable
method:
\Log::debug( print_r(Config::get('visits'), true));
then give me the resulting log?
I get this,
[2018-02-16 09:27:11] local.DEBUG: 1
You should get an array dumped instead, which is the whole configuration array.
Try this instead: Log::debug(print_r(Config::get('app'), true));
Yes, I tried this. I get the entire array from config/app.php for
Log::debug(print_r(Config::get('app'), true));
But for visits, i just get
[2018-02-16 09:31:08] local.DEBUG: 1
Are you sure you published the config file and that it is in your project/config
folder?
Yes, I have in the project folder. project_name/config/visits.php
I believe this is not something wrong with the library itself then, you should investigate why when you issue a Config::get('visits')
you are not receiving the configuration array.
Just to be sure, can you do the following
Replace config/visits.php contents as follows
<?php
return ['foo' => 'bar'];
Add a route as follows
Route::get('test', function(){
dump(\Config::get('visits'));
dump(\Config::get('database'));
});
Then navigate to http://yourproject/test and see output
Okay. I got the config visits file working. I had to clear the cache.
Ran php artisan config:cache
This worked.
in Visits.php (line 33)
Seems like your Session is null, which is also weird. Can i see your config/session.php?
Yes, here
`<?php
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
];
`
Use test route again.
Route::get('test', function(\Illuminate\Http\Request $request){
dump($request->getSession());
dump($request);
});
What's the output here?
I only get the dump of $request, the $request->getSession() gives empty. null.
That's your issue then, you have an empty session for some reason. I won't ask for your .env as it might contain private info such as passwords etc, but you should check there.
What driver are you using? If it is file, make sure your sessions directory is writable. If it is database, make sure you ran the session migration.
More info here https://laravel.com/docs/5.5/session
I'll be glad to give you more support, however i'm closing this as it doesn't seem related to the library.
Alright, thanks for your help and support.
I am using file-based sessions and sessions are being generated in the storage folder.
anyways, I shall check once again.
@joashp did you get this sorted?
@brazorf No, I tried with changing the session driver. Still no luck. I have a auth based system, once I login, the sessions are being created in the session folder. But for non auth users sessions are not being generated. Will be giving another shot, trying why it's not working.
@brazorf Alright, I got the sessions working. But when I enabled the plugin from the middleware, it still gave session null. So, I changed and moved the plugin to the middleware group. And it started working.
` protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, 'Foothing\Laravel\Visits\Middlewares\CountPageView', ],
'api' => [
'throttle:60,1',
'bindings',
],
];
`
Now, I have records in visits_buffer table, but no records in visits table. When do the records get inserted into visits table? I checked logs, no errors other than this.
[2018-02-17 05:20:55] local.DEBUG: Cache set pageviews:aggregate:default [2018-02-17 05:21:18] local.DEBUG: Cache hit pageviews:countOverallVisits:currentYear [2018-02-17 05:21:18] local.DEBUG: Cache set pageviews:countOverallVisits:currentYear [2018-02-17 05:21:18] local.DEBUG: Cache set pageviews:aggregate:currentYear
I might need to update the docs, as the config section mostly refer to versions of Laravel < 5.3.
Your visits table will populate according to your Schedule settings (see docs), however you can do the swap manually with a php artisan visits:buffer
I have followed the instructions, but when I visit any page. There are no records generated in visits and visits_buffer tables.