Stretch0
Stretch0

Reputation: 9251

Laravel 5 - Unable to call User class

I am trying to pull all users from my DB in my controller and then pass it to the view with the follow function.

public function carriers(){
    $aAllUsers = User::all();
    return view('carriers')->with("aAllUsers", $aAllUsers);
}

I am getting the following error

FatalErrorException in CarriersController.php line 24: Class 'App\Http\Controllers\User' not found in CarriersController.php line 24 at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'App\Http\Controllers\User' not found', 'file' => '/Users/andrewmccallum/Documents/webdev/mobileMe/app/Http/Controllers/CarriersController.php', 'line' => '24')) in HandleExceptions.php line 116 at HandleExceptions->handleShutdown()

As you already know, the user model comes included already in laravel 5 so unsure why it can't find a pre-existing class. Could it be my DB config?

Sorry if I haven't included enough information, I am not sure what else would be helpful so let me know if you would like me to post more code.

Upvotes: 0

Views: 331

Answers (1)

Anand Patel
Anand Patel

Reputation: 3943

Try this code, you need to include User class by using use statement in Laravel 5.

namespace App\Http\Controllers;

// write this to include User class
use App\User;

class CarriersController extends Copntroller
{
    public function carriers()
    {
        $aAllUsers = User::all();
        return view('carriers')->with("aAllUsers", $aAllUsers);
    }
}

Upvotes: 2

Related Questions