Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.3通知发送错误_Php_Laravel_Laravel 5.3 - Fatal编程技术网

Php Laravel 5.3通知发送错误

Php Laravel 5.3通知发送错误,php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,我正在尝试在我的Laravel 5.3应用程序中使用通知。我的第一步是尝试在新注册后立即发送欢迎通知。在阅读文档并遵循“Laravel 5.3中的新增功能”教程之后,我收到了一个“保存记录后调用undefined method Illumb\Notifications\Notification::send()”错误 下面的信息是我尝试过的最新信息,但我尝试的一切都失败了。当我把通知放在create方法下面时,我得到了一个保存,但没有发送通知。我把它放在前面只是为了看看会发生什么,因此出现了错误

我正在尝试在我的Laravel 5.3应用程序中使用通知。我的第一步是尝试在新注册后立即发送欢迎通知。在阅读文档并遵循“Laravel 5.3中的新增功能”教程之后,我收到了一个
“保存记录后调用undefined method Illumb\Notifications\Notification::send()”
错误

下面的信息是我尝试过的最新信息,但我尝试的一切都失败了。当我把通知放在create方法下面时,我得到了一个保存,但没有发送通知。我把它放在前面只是为了看看会发生什么,因此出现了错误

以下是欢迎辞:

    <?php

    namespace App\Notifications;

    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Notifications\Messages\MailMessage;
    use App\User;

    class WelcomeToDStrokeTennis extends Notification
    {
        use Queueable;

        protected $user;

        /**
         * Create a new notification instance.
         *
         * @return void
         */
        public function __construct(User $user)
        {


        }

        /**
         * Get the notification's delivery channels.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function via($notifiable)
        {
            return ['mail'];
        }

        /**
         * Get the mail representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return \Illuminate\Notifications\Messages\MailMessage
         */
        public function toMail($notifiable)
        {
            return (new MailMessage)
                ->line('MyApp Welcomes You.')
                ->action('Login To MyApp',         'http://dstroketennis.com')
                ->line('Thank you for trusting MyApp!');
        }

        /**
         * Get the array representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function toArray($notifiable)
        {
            return [
            //
            ];
        }
    }
更新: 我仍在尝试查找User的实例。我的最新尝试:

protected function create(array $data)
{
        User::create([
        'familyname' => $data['familyname'],
        'email' => $data['email'],
        'phone' => $data['phone'],
        'password' => bcrypt($data['password']),
    ]);
    $user = User::orderBy('created_at', 'desc')->first();
    $user->notify(new WelcomeToMyApp($user));
    return $user;


}
我得到错误:未定义属性:App\Notifications\welcometmyapp::$id

更新。。。节日快乐

我在执行dd($users)时显示以下数据。我在通知中添加了$data参数。我得到一个错误:

RegisterController.php第66行中的FatalThroTableError: 类型错误:传递给App\Http\Controllers\Auth\RegisterController::create()的参数2必须是App\User的一个实例,没有给定,在第33行的/home/ubuntu/workspace/vendor/laravel/framework/src/light/Foundation/Auth/RegistersUsers.php中调用

{ 使用可排队

protected $user;
protected $data;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct(array $data, User $user)
{
    $this->data = $data;
    $this->user = $user;
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['mail'];
}

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
                ->subject('MyApp Welcomes You.')
                ->greeting('You are now a registered user.')
                ->line('If you have not done so, please login and enter your player profile information')
                ->action('Login To D`Stroke Tennis', 'http://dstroketennis.com')
                ->line('Please call, text, or email if you have any problems or questions.');
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
    ];
}
}

解决方案:

protected function create(array $data)
{
     $user = User::create([
        'familyname' => $data['familyname'],
        'email' => $data['email'],
        'phone' => $data['phone'],
        'password' => bcrypt($data['password']),
    ]);

    $user->notify(new WelcomeToMyApp($user));
    return $user;        
}

参数也必须从通知类中删除,但这是用于此目的的代码。

这可能是因为
通知
是一个门面。 试用

use Notification;
而不是

use Illuminate\Notifications\Notification;

通知门面使用要求第一个参数作为应通知用户的集合,而不是提供请求数据。您应该在下面传递用户集合更改

    $user = User::create([
        'familyname' => $data['familyname'],
        'email' => $data['email'],
        'phone' => $data['phone'],
        'password' => bcrypt($data['password']),
    ]);

   $user->notify(new WelcomeToDStrokeTennis($data));
    return $user;

这对我来说是有意义的,但我得到了一个错误:类型错误:传递给App\Notifications\WelcomeToDStrokeTennis::\uu construct()的参数1必须是App\User的实例,给定数组,在第75行的/home/ubuntu/workspace/app/Http/Controllers/Auth/RegisterController.php中调用更改通知构造函数并从参数中删除用户实例,改为将其设置为类似$data=array()的数组。我必须在Laracasts.com上为答案提供帮助。参数必须从通知类中删除,并且$user必须用作参数。很抱歉与回复不同步。我做了更改使用通知;我继续得到$user是数组的引用。我原以为可以使用“Collections”获取新的用户实例,但错误更改为“调用数组上的成员函数notify()”。
use Notification;
use Illuminate\Notifications\Notification;
    $user = User::create([
        'familyname' => $data['familyname'],
        'email' => $data['email'],
        'phone' => $data['phone'],
        'password' => bcrypt($data['password']),
    ]);

   $user->notify(new WelcomeToDStrokeTennis($data));
    return $user;