36 lines
748 B
PHP
36 lines
748 B
PHP
<?php
|
|
|
|
namespace App\Jobs\Tasks;
|
|
|
|
use App\Models\Post;
|
|
use Exception;
|
|
|
|
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
|
use LaravelGoogleIndexing;
|
|
|
|
class PublishIndexPostTask
|
|
{
|
|
public static function handle(Post $post)
|
|
{
|
|
$post->published_at = now();
|
|
|
|
if ($post->save()) {
|
|
if (app()->environment() == 'production') {
|
|
$post_url = route('front.post', ['slug' => $post->slug]);
|
|
|
|
try {
|
|
IndexNow::submit($post_url);
|
|
} catch (Exception) {
|
|
}
|
|
|
|
try {
|
|
LaravelGoogleIndexing::create()->update($post_url);
|
|
} catch (Exception) {
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|