php - Laravel Cannot load Model from Controller


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.

enter image description here

enter image description here

enter image description here




YourGame Model does not belong to theGames\Controller namespace.

I assume from your structure that yourModel is not namespaced, so you have these 2 options:

  1. use Game; as you did forView andBaseController or

  2. $data['games'] = \Game::all();




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:

use Games\Model\Game;

People are also looking for solutions to the problem: php mysql code won't echo


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.