Ich arbeite an Laravel 5.4 Anwendung und versuche zu installieren spatie/laravel-activitylog v1.16 (alte Version, da ich nicht sicher bin, ob die neuere v2.4.3 wird Arbeiten mit 5.4) link to packageErweitern spatie laravel-activitylogs Activity Model und Hinzufügen neuer füllbarer
Mein Problem ist das Paket sagt, dass ich einen Verursacher mit dem Paket CausesActivity Trait hinzufügen kann. Ich habe es dem Unternehmensmodell hinzugefügt, weil jedes Modell ein Attribut Company_id hat, aber das hat nicht funktioniert. Ich habe ein Unternehmen mit vielen Benutzern möchte die Unternehmens-ID zur Tabelle beim Erstellen eines Protokolls hinzufügen. Ich habe ein CompanyLogActivity-Modell erstellt, das das Aktivitätsmodell erweitert und der Tabelle activity_log die Spalte company_id aus dem Paket (package) hinzugefügt und das neue Modell zur Konfigurationsdatei hinzugefügt hat.
Ich habe dann versucht:
belongsToTenant Trait ohne in
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Activity;
use HipsterJazzbo\Landlord\BelongsToTenants;
class CompanyActivityLogs extends Activity
{
use BelongsToTenants;
protected $table = ['activity_log'];
public $tenantColumns = ['company_id'];
}
Mit $ ausfüllbare auf dem Modell und Beobachtung für das Erstellen oder Speicher zu füllen company_id
<?php
namespace App\Observers;
use App\CompanyActivityLogs;
use Auth;
use Spatie\Activitylog\Models\Activity;
class CompanyActivity
{
public function creating($model)
{
$model->fill(['company_id' => Auth::user()->company_id])->save();
}
public function updating($model) {
$model->fill(['company_id' => Auth::user()->company_id])->save();
}
Dann nutzt Hinzufügen meines neu FirmaActivityLogs Modell
public static function boot() {
parent::boot();
CompanyActivityLogs::observe(new CompanyActivity());
}
Das hat nicht funktioniert und ich dachte, das wäre eine großartige Lösung. Ich habe versucht, CompanyActivityLogs für Activity (das Elternmodell) in der Beobachtung-Anweisung zu wechseln, und das hat nicht funktioniert.
Ich habe versucht, das auf das erweiterte Modell
public static function boot()
{
parent::boot();
static::creating(function($model)
{
$model->created_by = public static function boot()
{
parent::boot();
static::creating(function($model)
{
$model->created_by = Auth::user()->company_id;
//also tried $model->save(); here
});
};
Schließlich hinzuzufügen Ich habe versucht, es an die Mutter anhängen :: array
protected $fillable = ['company_id'];
public function toArray()
{
$array = parent::toArray();
foreach ($this->getMutatedAttributes() as $key)
{
if (! array_key_exists($key, $array)) {
$array['company_id'] = Auth::user()->company_id;
}
}
return $array;
}
ich eine Denk sie so viele verschiedene Möglichkeiten versucht würde helfen .