0

我在通知发送电子邮件中遇到问题我无法获取特定数据

当我尝试获取特定的数据时,例如 $this->equipment->id 它不起作用但如果我使用 $this->equipment 它将显示数组数据

在我的控制器中

        $equipment = Equipment::where('id','1')->get();
        Notification::send($users, new Equipment($equipment));

in my Notification
``<?php

namespace App\Notifications;

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

class Equipment extends Notification
{
    use Queueable;
    public $equipment;

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


    public function via($notifiable)
    {
        return ['mail'];
    }


    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line($this->equipment->id.'The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }


    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}


$this->equipment is working 
but $this->equipment->id is not working
4

1 回答 1

0

可能是构造函数中的 $equipment 是集合而不是对象,因此它可以获取属性,请尝试在调用通知的 $equipment 上使用 first() 而不是 get()

于 2019-08-30T08:06:39.230 回答