Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

homestead - Laravel database access denied

I am new to Laravel and am getting an error when trying to run a simple command in the controller Article::all(). The error is:

PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

Here is my .env file:

APP_ENV=local
APP_DEBUG=true
APP_KEY=v1xavEadi4rHv0EGn05zQvtVAtQRA9zo

DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

The controller:

namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppHttpRequests;
use AppHttpControllersController;

use AppArticle;

class ArticlesController extends Controller
{
    public function index() 
    {

        $articles = Article::all();
    }
}

and the model:

namespace App;

use IlluminateDatabaseEloquentModel;

class Article extends Model
{

    protected $fillable = [

        'name',
        'body'

    ];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Anyone else looking at this in the future with the same issue - restart the command prompt after changing the env file in windows. Restarting the server didn't work, but closing out of everything and then trying it again worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...