Alen
Alen

Reputation: 1291

Class not found when called in custom class in laravel

I have a file named

Helper.php and I have put it in composer.

"autoload": {
        "files": [
            "app/Http/Helper.php",
            "app/Notification.php"
        ]
    },

You can see that I have also put a model that is Notification model. but when I call this Notification in Helper.php it says class Notification not found..

function notify()
{
    $notify = new App\Notifcation;
    $notify = new Notifcation; //Also tried this

}

Upvotes: 0

Views: 982

Answers (3)

Ali Rasheed
Ali Rasheed

Reputation: 2817

First of all you don't need to add it in composer.

Secondly, check what you have written twice thrice because there can be typos that will stop your program from being executed

remove "app/Notification.php" from composer.json and dump-autoload it. Then use like this.

function notify()
{
    $notify = new App\Notification;
}

If you add this Notification Model in composer then it will always be autoloaded even if it is not used thus putting unnecessary pressure on your project.

Hope this helps

Upvotes: 3

Odin Thunder
Odin Thunder

Reputation: 3547

Write use App\Notification in your Helper.php than

$notify = new Notification();

Or you can use this:

$notify = new \App\Notification;

And just in case check your namespaces

Upvotes: 1

Peter Reshetin
Peter Reshetin

Reputation: 925

You have a typo in Notifcation. Try this:

function notify()
{
    $notify = new Notification;
}

Upvotes: 1

Related Questions