Composer autoload

Asked

Viewed 79 times

0

I’m having trouble in hr adding a class to my autoload, keeps giving Class Routes not found! Could someone help me?

inserir a descrição da imagem aqui

Composer.json

"autoload": {
    "psr-4": {
        "App\\Http\\Controllers\\": "app/Http/Controllers/"
    }
},

Routes.php

<?php

namespace App\Http\Controllers;

class Routes {

    public function route() {
        return 'Ola';
    }

}

index php.

<?php

require 'vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use App\Http\Controllers;

$mail = new PHPMailer(true);
$route = new Routes();

dd($route->route());

1 answer

2


You just included the namespace Controllers, then to use this class namespace you aind appreciate referencing it:

use App\Http\Controllers;

$routes = new Controllers\Routes();

If you want to instantiate the class without needing the namespace will need to include the class to the scope:

use App\Http\Controllers\Routes;

$routes = new Routes();

But this class Routes is a controller? If you are using something like MVC it seems very strange to me that you have this class inside this namespace.

  • Still n worked, ta dando Uncaught Error: Class 'App Http Controllers Routes' not found. http://prntscr.com/n7nk4h

Browser other questions tagged

You are not signed in. Login or sign up in order to post.