Laravel 5.8 , artisan commands error : Failed to parse dotenv file due to an invalid name

This is a general error related to parsing the .env file. You'll see this is indicated in the error e.g.

The environment file is invalid!
Failed to parse dotenv file due to unexpected whitespace. 
Failed at [This will fail].

In this example it was caused by having unescaped whitespace in the APP_NAME field i.e.

APP_NAME=This will fail

To fix, escape with quotes e.g.

APP_NAME="This is better"

This is general Error when we change our app name. To remove this error just do this.

APP_NAME=My Project Name 

to this

APP_NAME="My Project Name"

You just need to add "" course around name. Thanks


I found the cause of this problem.

It was because of line separator in .env file !

It must be CRLF not LF

My .env file was LF

see the screenshot to understand the solution