2017-09-19 1 views
0

비 개체의 속성을 얻으려고 노력하지만 난이 라인 인 오류 in PostPublished.php (line 66) 받고 있어요 : 여기Laravel 통지 내가 <a href="https://laravel-news.com/send-tweets-laravel-notifications" rel="nofollow noreferrer">Automatically Send Tweets through Laravel Notifications</a>을 사용하고

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 [ 
      // 
     ]; 
    } 
} 
내 전체 코드입니다

업데이트 :

게시물과 사용자 사이의 관계가 없으므로 오류가 변경되었습니다.

+0

'$ post-> user'이 있습니까? 나는 그것이 비어 있거나 비어 있다고 생각한다. –

+0

'post'가 연관된'user'를 가지고 있지 않기 때문이다. – linuxartisan

+0

@linuxartisan 어떻게 고칠 수 있는가? – mafortis

답변

0

Undefined property: stdClass::$errors in CouldNotSendNotification.php (line 9)

를 해결 내 트위터 응용 프로그램을 제거하고 지금은 모든 것이 작동 새로운 하나를 만들었습니다.

관련 문제