Skip to content

Commit

Permalink
feat: 紀錄投稿者的 User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kantai235 committed Jul 4, 2024
1 parent 81f9d02 commit 6c54e09
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function article(PublishArticleRequest $request)
'ads' => $picture['ads'],
];
$data['ip_address'] = $request->ip();
$data['user_agent'] = $request->header('User-Agent');

/**
* 將文字投稿寫入
Expand Down Expand Up @@ -123,6 +124,7 @@ public function picture(PublishPictureRequest $request)
'type' => 'picture',
];
$data['ip_address'] = $request->ip();
$data['user_agent'] = $request->header('User-Agent');

/**
* 將圖片投稿寫入
Expand Down
1 change: 1 addition & 0 deletions app/Domains/Social/Models/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Cards extends Model
'blockade_remarks',
'blockade_at',
'ip_address',
'user_agent',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Domains/Social/Services/CardsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function store(array $data = []): Cards
'config' => $data['config'],
'picture' => $data['picture'],
'ip_address' => $data['ip_address'],
'user_agent' => $data['user_agent'],
]);
} catch (Exception $e) {
DB::rollBack();
Expand Down Expand Up @@ -261,6 +262,7 @@ protected function createCards(array $data = []): Cards
'active' => $data['active'] ?? false,
'blockade' => $data['blockade'] ?? false,
'ip_address' => $data['ip_address'] ?? null,
'user_agent' => $data['user_agent'] ?? null,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function up(): void
$table->string('blockade_remarks')->nullable()->comment('封鎖原因');
$table->timestamp('blockade_at')->nullable()->comment('在什麼時候被封鎖');
$table->string('ip_address')->nullable()->comment('IP Address');
$table->string('user_agent')->nullable()->comment('User Agent');
$table->timestamps();
$table->softDeletes();
});
Expand Down
6 changes: 6 additions & 0 deletions database/seeders/Social/SocialCardsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function run()
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -70,6 +71,7 @@ public function run()
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand Down Expand Up @@ -103,6 +105,7 @@ public function run()
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -127,6 +130,7 @@ public function run()
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -151,6 +155,7 @@ public function run()
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -175,6 +180,7 @@ public function run()
'blockade_remarks' => "這是一則測試的封鎖文章訊息。",
'blockade_at' => now(),
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);
}

Expand Down

0 comments on commit 6c54e09

Please sign in to comment.