Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel can't find class in namespace

I using Laravel, I have a Model class under App/Models

<?php
namespace App\Models;

class TodoList extends \Eloquent{
  public function listItems(){
      return $this->hasMany('TodoItem');
  }
}

In my Controller I have included the namespace as follows:

namespace App\Http\Controllers;

...

use App\Models\TodoItem;
use App\Models\TodoList;

class TodoListController extends Controller

My method looks like this:

public function show($id)
{
    $list=TodoList::findOrFail($id);
    return \View::make('todos.show')->with('list', $todo_list);
}

but when I call to a request i get the error:

FatalErrorException in TodoListController.php line 75: Class 'App\Models\TodoList' not found

like image 332
Thomas Kaemmerling Avatar asked Mar 16 '23 12:03

Thomas Kaemmerling


2 Answers

Trying running composer dump-autoload. Basically your classes become cached so you need to tell Laravel to look for newly added classes.

like image 146
J.McLaren Avatar answered Mar 28 '23 05:03

J.McLaren


I'm not sure, just try this :

namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;
class TodoList extends Eloquent{
  public function listItems(){
      return $this->hasMany('TodoItem');
  }
}
like image 21
Kiran LM Avatar answered Mar 28 '23 05:03

Kiran LM