feat: Implement morph maps and historical migration
This commit is contained in:
parent
d68fc33bcb
commit
682da3dea8
@ -3,6 +3,7 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@ -26,6 +27,13 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
JsonResource::withoutWrapping();
|
||||
$this->configureDefaults();
|
||||
|
||||
Relation::morphMap([
|
||||
'user' => \App\Models\User::class,
|
||||
'dynamic' => \App\Models\Dynamic::class,
|
||||
'ledger' => \App\Models\Ledger::class,
|
||||
'mutation' => \App\Models\Mutation::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?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('messages', function (Blueprint $table) {
|
||||
DB::table('messages')->where('subject_type', 'App\\Models\\User')->update(['subject_type' => 'user']);
|
||||
DB::table('messages')->where('subject_type', 'App\\Models\\Mutation')->update(['subject_type' => 'mutation']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('messages', function (Blueprint $table) {
|
||||
DB::table('messages')->where('subject_type', 'user')->update(['subject_type' => 'App\\Models\\User']);
|
||||
DB::table('messages')->where('subject_type', 'mutation')->update(['subject_type' => 'App\\Models\\Mutation']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -202,16 +202,16 @@ function parseMessageContent(message: {
|
||||
// 2. Link subjects if found in the text
|
||||
if (message.subject_id && message.subject_type) {
|
||||
if (
|
||||
message.subject_type === 'App\\Models\\Mutation' ||
|
||||
message.subject_type === 'App\\Models\\Ledger'
|
||||
message.subject_type === 'mutation' ||
|
||||
message.subject_type === 'ledger'
|
||||
) {
|
||||
const ledgerId =
|
||||
message.subject_type === 'App\\Models\\Mutation'
|
||||
message.subject_type === 'mutation'
|
||||
? message.subject?.ledger_id
|
||||
: message.subject?.id;
|
||||
|
||||
const ledgerName =
|
||||
message.subject_type === 'App\\Models\\Mutation'
|
||||
message.subject_type === 'mutation'
|
||||
? message.subject?.ledger?.name
|
||||
: message.subject?.name;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user