Laravel-发送邮件返回错误无法返回非对象的属性

时间:2019-11-11 01:06:45

标签: php laravel email

我有一个非常奇怪的问题,当我在可邮寄的构建方法中发送电子邮件视图时,它可以正常发送,但是出现错误“尝试获取非对象的属性'视图'”,因此我可以发送邮件后重定向到页面。

可邮寄:

public function __construct($data)
    {
        $this->email = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {


         $url = URL::temporarySignedRoute(
         'verifyCustomer', now()->addMinutes(100),['email'=>$this->email]
        );


        return $this->from('support@xxxx.com')
                    ->view('validate_email')->with([
                        'url' => $url,
                        'email' => $this->email
                    ]);

        dd('doesent work here');
    }

注册控制器:

protected function createCustomer(Request $request)
    {
        // dd($request->all());
        // $this->validator($request->all())->validate();
        $validator = Validator::make($request->all(), [
            'name' => ['required', 'alpha_dash', 'string', 'max:25', 'unique:customers'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:customers'],
            'password' => ['required', 'string', 'min:6', 'confirmed'],
        ]);
        if ($validator->fails())
        {
            $messages = $validator->messages();
            return Redirect::back()->withErrors($validator)->withInput();
            foreach($errors->all() as $error) {
            echo $error;
        }
        }
        elseif ($validator->passes())
        {
            $customer = customer::create([
                'name' => $request['name'],
                'email' => $request['email'],
                'password' => Hash::make($request['password']),
                'VerifyToken' => Str::random(40),
            ]);

            $customer->SendEmailVerificationNotification();    

            return redirect()->intended('auth/login');
        }
    }

SendEmailVerificationNotification:

class SendEmailVerificationNotification
{
    /**
     * Handle the event.
     *
     * @param  \Illuminate\Auth\Events\Registered  $event
     * @return void
     */
    public function handle(Registered $event)
    {
        if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
            $event->user->sendEmailVerificationNotification();
        }
    }
}

sendEmailVerification功能:

 public function sendEmailVerificationNotification()
    {
        $this->notify(new \App\Notifications\account_verification_notification);
    }

account_verification_notification:

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)
    {

        Mail::to($notifiable['email'])->send(new validate_email($notifiable['email']));
        // return (new MailMessage)
        //             ->line('The introduction to the notification.')
        //             ->action('Notification Action', url('/'))
        //             ->line('Thank you for using our application!');
    }

任何帮助都绝对是太棒了!因为这是第三天遇到这个错误:( 谢谢:)

0 个答案:

没有答案