Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

canadianlover's avatar

FatalThrowableError in GamesController.php line 45: -Class 'App\Http\Controllers\App\Games' not found

I have been trying to make a simple gambling website where players face each other to a coin toss. Whoever picks heads or tails wins the Bitcoin. I have the following routes file;

'''<?php

/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */

Route::get('/', 'PagesController@index');

Route::resource('games', 'GamesController');

Route::Controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\Passwordcontroller' ]);'''

and this is my GamesController:

'''<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class GamesController extends Controller { /** * create new instance of the game controller */ public function __construct()

{
    $this->middleware('auth');
}

/**
 * show all games pending a partner
 */

public function index()
{
    return 'The following users are ready to play';
}

/**
 * Show a page to create new game
 */

public function create()
{
    // create a new game

    // load view to create game

    return view('pages.create');
}

public function show() { // determine weather the outcome is heads or tails return App\Games::all();

} }'''

I am still fairly new to the laravel framework and any help I get is greatly appreciated. i've been at this all morning and can't find a solution.

0 likes
4 replies
Jaytee's avatar

You still need to import the base controller and Games model. This is standard php. At the top of your page add:

use App\Http\Controllers\Controller; // use the base controller so that your custom controller can extend the functionality
use App\Games; / / you can then do Games::all(); 

// If you don't import these, you need to give the full namespace path such as
// return \App\Games::all();
canadianlover's avatar

Thanks for your reply. I am still trying to add faker data to my project. i have tried your code in my Games module as well as my routes file and I still encounter errors with the factory function. I am a bit confused. any help is greatly appreciated.

awarren's avatar
awarren
Best Answer
Level 1

Just a side note. Anytime you see "Class 'App\Http\Controllers\App\SomeClass' not found" thrown from a controller it usually means you've referenced a class without "use". If you want to do it without "use" you need to add root to the classes namespace - \App\SomeClass.

Please or to participate in this conversation.