PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 5, 2022

[FIXED] How to fix Class 'App\Http\Controllers\Notification' not found in laravel?

 January 05, 2022     facade, laravel, laravel-5, php     No comments   

Issue

I have a Controller which listens to a new Schedule creation and sends the result back to the view via ajax. Inside of it I want to add a Notification to send email to the user once the Schedule cannot be completed due to a lack of resources at that specific date and time.

The problem is that I get the error below:

Class 'App\Http\Controllers\Notification' not found in /laravel/app/Http/Controllers/DadosAgendamentoController.php on line 89

The folder structure is this:

-app
    -Http
        -Controllers 
            DadosAgendamentoController.php
    -Notifications
        AgendamentoPendente.php

DadosAgendamentoController.php head code:

namespace App\Http\Controllers;

use Input;
use Request;
use App\Servicos;
use App\Disponibilidades;
use App\Estabelecimentos;
use App\HorariosEstabelecimento;
use App\Agendamento;
use App\User;
use App\Notifications\AgendamentoPendente;

line 88 and 89:

$user = User::where('id',1)->get();
Notification::send($user, new AgendamentoPendente(1));

Trough my Controller I can access all the classes above, but not the AgendamentoPendente

My goal is to send an email do the admin so he can suggest a new date and time to the client when the resources are not available at the desired date and time.

How can it be fixed? Can I access the class in this Controller? How?


Solution

Notifications may be sent in two ways: using the notify method of the Notifiable trait or using the Notification facade.

https://laravel.com/docs/5.3/notifications#sending-notifications

Option 1

You can use notify() method:

$user->notify(new AgendamentoPendente(1));

Also, make sure User class uses Notifiable trait:

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

Option 2

Using facade with full namespace:

\Notification::send($user, new AgendamentoPendente(1));


Answered By - Alexey Mezenin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing