Add (rss post): domain

This commit is contained in:
2023-11-23 21:30:33 +08:00
parent e4eb51b2b7
commit 0a1987f593
4 changed files with 47 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ public function handle(): void
if (is_null($rss_post)) {
$rss_post = new RssPost;
$rss_post->post_url = $raw_post->link;
$rss_post->post_domain = get_domain_from_url($raw_post->link);
$rss_post->source = $raw_post->source;
$rss_post->source_url = $raw_post->source_url;
$rss_post->title = remove_newline($raw_post->title);

View File

@@ -54,6 +54,7 @@ class RssPost extends Model implements Feedable
'source',
'source_url',
'post_url',
'post_domain',
'title',
'slug',
'body',

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('rss_posts', function (Blueprint $table) {
$table->string('post_domain')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('rss_posts', function (Blueprint $table) {
$table->dropColumn('post_domain');
});
}
};

View File

@@ -53,6 +53,23 @@
Route::get('/crawlTask', [App\Http\Controllers\Tests\TestController::class, 'crawlTask']);
Route::get('/set_domain', function (Request $request) {
$last_record = RssPost::whereNull('post_domain')->orderBy('id', 'DESC')->first();
for ($i = 1; $i <= $last_record->id; $i++) {
$rss_post = RssPost::find($i);
if (!is_null($rss_post))
{
$rss_post->post_domain = get_domain_from_url($rss_post->post_url);
$rss_post->save();
}
}
return 'ok';
});
Route::get('/set_keywords', function (Request $request) {
$last_record = RssPost::where('keyword_saved', false)->orderBy('id', 'DESC')->first();