我正在使用Automatically Send Tweets through Laravel Notifications,但我收到错误in PostPublished.php (line 66)
,这就是这一行:
if ( ! $post->user->twitter_username or $post->user->id == 1) return false;
这是PostPublished
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterStatusUpdate;
use App\Post;
use App\User;
class PostPublished extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [TwitterChannel::class, TelegramChannel::class];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toTelegram($post)
{
return TelegramMessage::create()
->to('@lavtest')
->content($post->title .' http://domainxxx.com/blog/article/'. $post->slug);
}
//twitter
public function toTwitter($post)
{
$title = $post->title;
if ($handle = $this->twitterHandle($post)) {
$title = $title .' via '. $handle;
}
return new TwitterStatusUpdate($title .' https://domainxxx.com/blog/article/'. $post->slug, [$post->image]);
}
protected function twitterHandle($post)
{
if ( ! $post->user->twitter_username or $post->user->id == 1) return false;
if ($post->user->twitter_username and ! starts_with($post->user->twitter_username, '@')) {
$post->user->twitter_username = '@'.$post->user->twitter_username;
}
return $post->user->twitter_username;
}
//end twitter
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
更新
我在帖子和用户之间没有关系,我现在已将错误更改为Undefined property: stdClass::$errors in CouldNotSendNotification.php (line 9)
答案 0 :(得分:0)
<强>解决强>
我删除了我的Twitter应用并创建了新应用,现在一切正常。