icelander
1 year ago

i cant seem to get any notification on my notification table in my database

Posted 1 year ago by icelander

hi. my aim is to get notifications sent to my notifications table each time I run this method contained in my controller. I truncated it just to show the problematic part below:

 $fixedpays = FinalPayment::insert([
            'totalAmount'=>$amount,
            'location'=>$locations,
            'verifiedproblem'=>$carts,
            'vehicle'=>$vehiclenames,
            'paymentsID'=>$ref,
            'user_id' => auth()->user()->id,
            'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
             'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
  ]);
        $users = auth()->user()->id;
        User::find($users)->notify(new MergedMechanic);
        return redirect()->to('second')->with('success','Successfully paid main charges. The    Mechanic can start work immediately!');
       
       }

in summary, I want to fire up that notification to the particular logged in user when payments have been made. but it doesn't seem to work. also in my view page, nothing is displayed in the notification icon

 @guest
        @else
        <div class="header-menu">
               
            <div class="col-sm-7">
                <a id="menuToggle" class="menutoggle pull-left"><i class="fa fa fa-tasks"></i></a>
                <div class="header-left">
                    <button class="search-trigger"><i class="fa fa-search"></i></button>
                    <div class="form-inline">
                        <form class="search-form">
                            <input class="form-control mr-sm-2" type="text" placeholder="Search ..." aria-label="Search">
                            <button class="search-close" type="submit"><i class="fa fa-close"></i></button>
                        </form>
                    </div>
                
                    <div class="dropdown for-notification">
                      <button class="btn btn-secondary dropdown-toggle" type="button" id="notification" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <i class="fa fa-bell"></i>
                        <span class="count bg-danger">{{ Auth::user()->notifications->count() }} </span>
                      </button>
                      <div class="dropdown-menu" aria-labelledby="notification">
                          @foreach(auth()->user()->unreadNotifications as $notification)
                        <p class="red">You have  Notification</p>
                        <a class="dropdown-item media bg-flat-color-1" href="#">
                            <i class="fa fa-check"></i>
                            <p> {{$notification->type}} </p>
                        </a>@endforeach

This is part of my MergedToMechanic file in the notification folder

public function __construct()
    {
        //
    }

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

    /**
     * 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 toDatabase($notifiable)
    {
        return [
            'data'=>'A mechanic has been assigned to you. Thanks'
        ];
    }

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

Please sign in or create an account to participate in this conversation.