PHP code example of mehrabhossain / loglens
1. Go to this page and download the library: Download mehrabhossain/loglens library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mehrabhossain / loglens example snippets
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use MehrabHossain\LogLens\Facades\LogLens;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
// Authorize dashboard view access (Read-Only)
LogLens::auth(function ($request) {
$user = $request->user();
return $user && in_array($user->email, [
'[email protected] ',
'[email protected] ',
'[email protected] ',
]);
});
// Authorize destructive actions (clearing/deleting log files)
LogLens::destructiveAuth(function ($request) {
return $request->user()?->email === '[email protected] ';
});
}
}
use Illuminate\Support\Facades\Gate;
Gate::define('viewLogLens', function ($user) {
return $user->hasRole('admin') || $user->hasRole('super-admin');
});
Gate::define('manageLogLens', function ($user) {
return $user->hasRole('super-admin');
});
// config/loglens.php
'middleware' => [
'web',
'auth', // <-- Automatically redirects unauthenticated guests to /login
],
LogLens::auth(function ($request) {
$allowedIps = [
'127.0.0.1',
'10.0.1.50',
'203.0.113.10', // Corporate static IP
];
return in_array($request->ip(), $allowedIps, true);
});
// config/loglens.php
'auth' => [
'gate' => 'viewLogLens',
'destructive_gate' => 'manageLogLens',
'allow_local_by_default' => false, // <-- Enforces authorization on local environment
],
bash
php artisan vendor:publish --tag=loglens-config
bash
php artisan vendor:publish --tag=loglens-views
bash
php artisan serve
bash
php artisan loglens:apache-collect
bash
vendor/bin/phpunit tests/Security/ZeroDatabaseQueryTest.php
vendor/bin/phpunit tests/Security/ZeroExtraQueryTest.php