4

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

1
  • If you're using Laravel5, model classes doesn't extend Eloquent. They extend Model. Also, check if your TodoList class file is present at app/Models folder. Commented Jul 6, 2015 at 13:22

4 Answers 4

6

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

Sign up to request clarification or add additional context in comments.

Comments

1

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');
  }
}

Comments

1

Here is the code from the docs, but for your example. Note the use Model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TodoList extends Model {

    //insert public function listItems() here

}

Hope this is helpful!

Comments

0

Make sure the file is in the correct folder and has the same name caption as the Class you want to import.

If the caption of the file "TodoList" is not TodoList.php but Todolist.php for example, Laravel wont find it.

Depending on your setup running "composer dump" might help to refresh autoload files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.