Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOsamu Fujimoto
45,636 PointsI am stuck in the Eloquent ORM in Laravel Basics
I am using larval 5 as I follow the course Laravel Basics. I got an error "FatalErrorException in TodoListController.php line 21: Class 'App\Http\Controllers\TodoList' not found" I couldn't figure out this error. Please help me solve this problem.
I created the models file inside app file. inside models, I placed TodoList.php.
in TodoList.php <?php
class TodoList extends Eloquent {}
in TodoListController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller;
class TodoListController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { $todo_lists = TodoList::all(); $todo_lists = \App\TodoList::all(); return view('todos.index')->with("todo_lists", $todo_lists); }
2 Answers
Corey Cramer
9,453 PointsYou can solve this two different ways and I'll demonstrate both below. Both changes involve your controller as your model is fine. Regardless of which solution you decide to use, you should not assign the variable $todo_lists twice.
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\ToDolist; // Alias your model so that it can be used inside of your controller
class TodoListController extends Controller {
/** * Display a listing of the resource. * * @return Response */
public function index()
{
$todo_lists = TodoList::all();
return view('todos.index')->with("todo_lists", $todo_lists);
}
}
Or
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class TodoListController extends Controller {
/** * Display a listing of the resource. * * @return Response */
public function index()
{
$todo_lists = \App\TodoList::all();
return view('todos.index')->with("todo_lists", $todo_lists);
}
}
Osamu Fujimoto
45,636 PointsThank you for your help!! I could solve this problem!
Jack McDowell
37,797 PointsJack McDowell
37,797 PointsThank you, I noticed that I had a . instead of a , on the last line of your second solution!