Biguá Biguá - 2 months ago 17
PHP Question

Class not found exception in a route of slim framework

I'm starting with Slim+eloquent+twig (using this presentation ) and getting this error:

Type: Error
Message: Class 'Localizacao' not found
File: /Users/Bigua/Sites/salas/src/routes.php
Line: 19

I'm trying to list all from a table and pass it to my view. The command "composer update" don't returned any problem.

here my code:


"name": "slim/slim-skeleton",
"description": "A Slim Framework skeleton application for rapid development",
"keywords": ["microframework", "rest", "router", "psr7"],
"homepage": "",
"license": "MIT",
"authors": [{
"name": "Josh Lockhart",
"email": "",
"homepage": ""
"require": {
"php": ">=5.5.0",
"slim/slim": "^3.1",
"monolog/monolog": "^1.17",
"illuminate/database": "~5.1",
"slim/twig-view": "^2.1"
"autoload": {
"psr-4": {
"App/Models\\": "app/models"


$app->get('/sala/add', function ($request, $response, $args) {
$this->logger->info("Slim-Skeleton '/salas/add' route");
// Render index view
$args['locais'] = Localizacao::all();
$this->logger->info("locais" . $args);
return $this->renderer->render($response, 'add_sala.html.twig', $args);


namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Localizacao extends Eloquent {
protected $table = 'localizacao';

protected $primaryKey = 'id_local';
public $timestamps = false;

I had read many similar topics here and seems to me that is a problem with namespaces, but I just don't get it where its wrong. Sorry if this is a noob question.


The solution its following the two answers, from @marcin-nabiaƂek and @geggleto :

Fixed the psr-4:

"psr-4": {
"App\\Models\\": "app/models"

And using namespace correctly:


Tnx a lot !!!


Your composer entry for PSR-4 autoloading is incorrect

"psr-4": {
    "App/Models\\": "app/models"

Should be

"psr-4": {
    "App\\Models\\": "app/models"