shetabit / visitor

a laravel package to work with visitors and retrieve their informations
MIT License
527 stars 68 forks source link

How can I add middleware to log automatically #13

Closed Expertweblancer closed 4 years ago

Expertweblancer commented 4 years ago

Detailed description

Hello I am using Laravel 7.0 composer install and migration successfully done I wanted to add middleware to log automatically. I tried many times but failed Can you give me a tip to solve this issue

Context

I want to track the visitors on my web admin panel

Possible implementation

middleware issue

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

khanzadimahdi commented 4 years ago

add the below middleware into your route middlewares:

Shetabit\Visitor\Middlewares\LogVisits

then use Shetabit\Visitor\Traits\Visitable trait in all models which can be visited by users.

and use Shetabit\Visitor\Traits\Visitor trait in your user model.

Expertweblancer commented 4 years ago

http://prntscr.com/ssdkhh http://prntscr.com/ssdkzz

And then what is the next step? I cant still see the logs in the database visitor tables

khanzadimahdi commented 4 years ago

you have introduced the visitors middleware to Laravel's kernel.

add it on the routes that you want their logs: for example in routes/web.php :

Route::middleware(['visitors'])->get('/', 'exampleController@method');

you have imported trait in your model, then you should use it in model like the below:

class YourModel extends Model {
    use Visitable;

}
Expertweblancer commented 4 years ago

I already tried like that before I am getting errors This is the log file thanks for your help

https://www.dropbox.com/s/9g9fva3yxxunxf8/laravel.log?dl=0 hope you to help me finally

Expertweblancer commented 4 years ago

[2020-06-02 14:07:28] local.ERROR: Target class [App\Http\Shetabit\Visitor\Middlewares\LogVisits] does not exist. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target class [App\Http\Shetabit\Visitor\Middlewares\LogVisits] does not exist. at E:\2020\5.

khanzadimahdi commented 4 years ago

in your kernel, add a back slash before middleware's path:

 'visitors' => \Shetabit\Visitor\Middlewares\LogVisits::class,

the error is because of that.

Expertweblancer commented 4 years ago

same issue I am finding the issue

Expertweblancer commented 4 years ago

[2020-06-02 14:17:07] local.ERROR: Driver not selected or default driver does not exist. {"exception":"[object] (Shetabit\Visitor\Exceptions\DriverNotFoundException(code: 0): Driver not selected or default driver does not exist. at E:\2020\5. May\laravel-movies\vendor\shetabit\visitor\src\Visitor.php:341) [stacktrace]

Expertweblancer commented 4 years ago

Driver not selected or default driver does not exist.

khanzadimahdi commented 4 years ago

publish package configs:

php artisan vendor:publish

a config file must be exists after that: config/visitor.php

Expertweblancer commented 4 years ago

I already publish vendor There is visitor.php in config directory

khanzadimahdi commented 4 years ago

have you cached configs? you need to clear cache

php artisan config:clear
Expertweblancer commented 4 years ago

Wow php artisan config:cache

Expertweblancer commented 4 years ago

You are great. What is your email address or preferred communication? If I have any project, we can work together Thanks for your valuable time

khanzadimahdi commented 4 years ago

Your welcome. my email: khanzadimahdi@gmail.com

dunialmasmari commented 3 years ago

it will be a good idea if you added this explanation to your install and config details(the setup documentation) ,good job, thank you