laravel-auditing
laravel-auditing copied to clipboard
Auditing a Multi-tenancy Application
Q | A |
---|---|
Bug? | no |
New Feature? | no |
Framework | Laravel |
Framework version | 5.x.y |
Package version | 6.x.y |
PHP version | 7.x.y |
Actual Behaviour
This package has helped me a great deal with handling auditing in many applications. Kudos to all the contributors.
I am building a multi-tenancy application that creates a new database for every new subscriber.
The challenge is auditing is not able to identify a current tenant database thus it tries to locate the audits table in the default DB, which does not have it. See error thrown:
lluminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mlss_tenant.audits' doesn't exist (SQL: insert into
audits (
old_values,
new_values,
event,
auditable_id,
auditable_type,
user_id,
user_type,
url,
ip_address,
user_agent,
tags,
updated_at,
created_at) values ([], {"name":"Ofloxacin","id":8}, created, 8, App\Antibiotics, 1, App\User, http://www.topmed.localhost:8000/utility/antibiotics-save, 127.0.0.1, Mozilla/5.0 (Macintosh; Intel
Expected Behaviour
I want to store all audits in the current tenant's DB
Steps to Reproduce
List all the steps needed to reproduce the issue you're having.
/* |--------------------------------------------------------------------------
Audit Driver Configurations |
---|
Available audit drivers and respective configurations. |
*/
'drivers' => [
'database' => [
'table' => 'audits',
'connection' => 'system',
],
],
/* |--------------------------------------------------------------------------
Database Connection |
---|
*/ |
'system' => [ |
'driver' => 'mysql',
'host' => env('TENANCY_HOST', '127.0.0.1'),
'port' => env('TENANCY_PORT', '3306'),
'database' => env('TENANCY_DATABASE', 'tenancy'),
'username' => env('TENANCY_USERNAME', 'tenancy'),
'password' => env('TENANCY_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
/* |--------------------------------------------------------------------------
Model |
---|
*/ |
namespace App;
use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable; use Tenancy\Affects\Connections\Support\Traits\OnTenant; use Tenancy\Identification\Contracts\Tenant;
class Antibiotics extends Model implements Auditable { use OnTenant; use \OwenIt\Auditing\Auditable;
protected $fillable = ['name'];
}
What am I doing wrong? Thanks
Though I don't have aa specific answer for the setup you have, I can say that I am currently building an app with multi-tenancy using https://tenancyforlaravel.com/
The only change I had to make after requiring this package was moving its migration file over to a "tenancy" subfolder in my migrations folder. Everything else worked out of the box.
Closed due to inactivity