0

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.

1
  • Sounds like you need to include 'use App\User;' at the top of your controller. Commented Mar 13, 2015 at 3:07

1 Answer 1

2

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);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.