Add (facebook)
This commit is contained in:
@@ -28,7 +28,7 @@ public function redirect(Request $request, $slug)
|
||||
|
||||
public function index(Request $request, $category_slug, $slug)
|
||||
{
|
||||
$post = Post::where('slug', $slug)->where('status', 'publish')->first();
|
||||
$post = Post::where('slug', $slug)->whereIn('status', ['publish','future'])->first();
|
||||
|
||||
if (is_null($post)) {
|
||||
return abort(404);
|
||||
|
||||
@@ -7,9 +7,21 @@
|
||||
use Illuminate\Http\Request;
|
||||
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
use App\Models\Post;
|
||||
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Notifications\PostWasPublished;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
public function notification(Request $request)
|
||||
{
|
||||
$post = Post::find(1);
|
||||
|
||||
Notification::route('facebook','default')->notify(new PostWasPublished($post));
|
||||
}
|
||||
|
||||
public function imageGen(Request $request)
|
||||
{
|
||||
$image_url = 'https://cdn.futurewalker.co/post_images_2/whats-next-for-openai-after-ceo-sam-altmans-ouster-1700439234754.jpg';
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
use Exception;
|
||||
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Notifications\PostWasPublished;
|
||||
|
||||
class PublishIndexPostTask
|
||||
{
|
||||
@@ -35,6 +37,13 @@ public static function handle(int $post_id)
|
||||
|
||||
}
|
||||
|
||||
Notification::route('facebook','default')->notify(new PostWasPublished($post));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
app/Notifications/PostWasPublished.php
Normal file
41
app/Notifications/PostWasPublished.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
use NotificationChannels\FacebookPoster\FacebookPosterChannel;
|
||||
use NotificationChannels\FacebookPoster\FacebookPosterPost;
|
||||
|
||||
class PostWasPublished extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct($post)
|
||||
{
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return [FacebookPosterChannel::class];
|
||||
}
|
||||
|
||||
|
||||
public function toFacebookPoster($notifiable) {
|
||||
return (new FacebookPosterPost(str_first_sentence($this->post->bites)))->withLink(route('front.post', ['slug' => $this->post->slug, 'category_slug' => $this->post->category->slug]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user