How can I add middleware to log automatically
Expertweblancer opened this issue · 16 comments
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.
- Version used (e.g. PHP 7.2, HHVM 3):
- Operating system and version (e.g. Ubuntu 19.04, Windows 10):
- Link to your project:
- ...
- ...
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.
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
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;
}
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
[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.
in your kernel, add a back slash before middleware's path:
'visitors' => \Shetabit\Visitor\Middlewares\LogVisits::class,
the error is because of that.
same issue
I am finding the issue
[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]
Driver not selected or default driver does not exist.
publish package configs:
php artisan vendor:publish
a config file must be exists after that: config/visitor.php
I already publish vendor
There is visitor.php in config directory
have you cached configs? you need to clear cache
php artisan config:clear
Wow
php artisan config:cache
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
Your welcome.
my email: khanzadimahdi@gmail.com
it will be a good idea if you added this explanation to your install and config details(the setup documentation) ,good job, thank you