After you require the package. When you do php artisan migrate
you will notice a new migration/table getting migrated.
It is the create_access_logs_table
migration.
That is because the AccessLogMiddleware
saves logged api endpoints in this table.
To use the AccessLogMiddleware
, all you have to do is wrap the middleware access.log
around your desired endpoints like below
// api.php
Route::middleware(['access.log'])->group(function () {
Route::get('/hello', function () {
return 'Hello World';
});
});
After you wrapped the access.log
middleware around your api endpoints.
Now, if you hit that endpoint yourUrl:8000/hello
it will return the string Hello World.
If you go to your access log table now you will see that the endpoint information were saved to the access log database table.
It has information like:
You can optionally publish the Models and the Migrations of this package If you want to customize anything:
You can publish the package's models through this command:
php artisan vendor:publish --tag=lara-util-x-models
You can publish the package's migrations through this command:
php artisan vendor:publish --tag=lara-util-x-migrations