php - Laravel Cannot load Model from Controller
147
I was looking at this tutorial for laravel 4 by Dayle Rees. I decided to create my own and I encountered a problem with my Controller not finding the model I created for my table database named 'games'. What could be the problem here? Some screenshots below.
Answer
Solution:
Your
Game Model
does not belong to theGames\Controller
namespace.I assume from your structure that your
Model
is not namespaced, so you have these 2 options:use Game;
as you did forView
andBaseController
or$data['games'] = \Game::all();
Answer
Solution:
The error tells you search for a class Game in the namespace Games\Controller\Game. But your Model class is not in this namespace.
You can resolve this by add the use at the top of your class: