Fix default timestamp for activity logs (#468)

* fix default timestamp for activity logs

* fix phpstan
This commit is contained in:
Boy132 2024-07-10 08:36:24 +02:00 committed by GitHub
parent 1c1c8c0cc6
commit 447e889a4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -140,6 +140,10 @@ class ActivityLog extends Model
{
parent::boot();
static::creating(function (self $model) {
$model->timestamp = Carbon::now();
});
static::created(function (self $model) {
Event::dispatch(new ActivityLogged($model));
});

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('activity_logs', function (Blueprint $table) {
$table->timestamp('timestamp')->default(null)->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('activity_logs', function (Blueprint $table) {
$table->timestamp('timestamp')->useCurrent()->change();
});
}
};