nickshek/laravel-request

A simple package to log all the requests in a database for Laravel 5

v0.1.0 2016-06-26 08:44 UTC

This package is not auto-updated.

Last update: 2024-12-21 21:19:52 UTC


README

Latest Version on Packagist Software License Build Status Quality Score

A simple package to log all the requests in a database for Laravel 5.

Inspired by django-request

Note: This package is still very alpha!

Install

You can install the package via composer:

composer require nickshek/laravel-request

Install service provider

// config/app.php
'providers' => [
    ...
    LaravelRequest\LaravelRequestServiceProvider::class,
];

publish migrations and config file

php artisan vendor:publish --provider="LaravelRequest\LaravelRequestServiceProvider"

Afterwards you can edit the file config/laravel-request.php to suit your needs.

Run migration to create required tables

php artisan migrate

By default, the middleware \LaravelRequest\Middleware\LogAfterRequest::class enables logging on all pages. You'll probably want to inherit your own class containing you application's logging rule handler.

namespace App\Http\Middleware;
// app/Http/Middleware/LogAfterRequestExceptAdmin.php
use LaravelRequest\Middleware\LogAfterRequest;

class LogAfterRequestExceptAdmin extends LogAfterRequest
{
  /**
  * @return bool
  */
  protected function shouldLogRequest($request, $response)
  {
    return $request->segment(1) !== 'admin';
  }
}

Next, simply register the newly created class in your middleware stack.

// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \App\Http\Middleware\LogAfterRequestExceptAdmin::class,
    ];

    // ...
}

That's it!

License

The MIT License (MIT). Please see License File for more information.