参数1传递给app \ notifications \ newInstalasi :: __ construct()必须是app \ models \ user,app \ models \ instalasi的实例

发布于 2025-01-30 11:58:36 字数 2483 浏览 2 评论 0原文

我正在使用Laravel 8中的实时使用Pusher进行项目,然后我得到了此错误。 \ Models \ instalasi给出,在C:\ Xampp \ htdocs \ rsud \ laporan_teknisi_improvement \ app \ observers \ instalasiobserver.php中给出了c:\ xampp \ htdocs \ rsud \ rsud \ rsud \ rsud \ rsud \ rsud \ rsud \ instalasiobserver.php中给出的\。

在我的通知/newInstalasi.php代码中:

<?php

namespace App\Notifications;

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

class NewInstalasi extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */

     protected $user, $instalasi;
    public function __construct(User $users, Instalasi $instalasi)
    {
        $this->instalasi = $instalasi;
        $this->users = $users;
    }

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

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'user_id' => $this->users->id,
            'user_name' => $this->users->name,
            'instalasi' => $this->instalasi->nama,
        ];
    }
}

以及在observer/instalasiobserver.php代码中:

<?php
namespace App\Observers;

use App\Notifications\NewInstalasi;
use App\Models\User;
use App\Models\Instalasi;

class InstalasiObserver
{
    public function created(Instalasi $instalasi)
    {
        $author = $instalasi->user;
        $users = User::all();
        foreach ($users as $user) {
            $user->notify(new NewInstalasi($instalasi,$author));
        }
    }
}

i am doing project with notification real time use pusher in laravel 8, and then i have got this error "Argument 1 passed to App\Notifications\NewInstalasi::__construct() must be an instance of App\Models\User, instance of App\Models\Instalasi given, called in C:\xampp\htdocs\rsud\laporan_teknisi_improvement\app\Observers\InstalasiObserver.php on line 15".

in my Notification/NewInstalasi.php codes :

<?php

namespace App\Notifications;

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

class NewInstalasi extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */

     protected $user, $instalasi;
    public function __construct(User $users, Instalasi $instalasi)
    {
        $this->instalasi = $instalasi;
        $this->users = $users;
    }

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

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'user_id' => $this->users->id,
            'user_name' => $this->users->name,
            'instalasi' => $this->instalasi->nama,
        ];
    }
}

and in Observer/InstalasiObserver.php codes :

<?php
namespace App\Observers;

use App\Notifications\NewInstalasi;
use App\Models\User;
use App\Models\Instalasi;

class InstalasiObserver
{
    public function created(Instalasi $instalasi)
    {
        $author = $instalasi->user;
        $users = User::all();
        foreach ($users as $user) {
            $user->notify(new NewInstalasi($instalasi,$author));
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文