简体   繁体   中英

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

}

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

You have a typo in Notifcation . Try this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM