Laravel SQLSTATE [HY000] [2002]连接被拒绝当“控制器”中的命令但通常在修补程序中的单词

So I have trying to make Autocomplete in my Project (Dictionary), and the SQL Worked normally if testing SQL Command using #Tinker.

# php artisan tinker

Psy Shell v0.9.9 (PHP 7.1.19 — cli)
>>> use App\WordsList;
>>> WordsList::where('Translation', 'english')->first();
=> App\WordsList {#2962
     ID: 4,
     Word: "اَلْإِنْكِلِيزِيَّة",
     SimpleWords: "الإنكليزية",
     Translation: "english",
     Views: null,
   }
>>> 

but if make that in AutoComplete Controller like this:

    public function search(Request $request) 
    {
          $search = $request->get('term');

          $result = WordsList::where('Translation', 'LIKE', '%'. $search. '%')->first();

          return response()->json($result);

    } 

Web file (Routes)

Route::get('autocomplete', 'AutoCompleteController@search');

if found this problem:

## (URL) http://127.0.0.1:8000/autocomplete/?term=english

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `WordsList` where `Translation` LIKE %english% limit 1)

I've had this happen to me on several occasions. More often than not, it is helpful to take a look at your .env file.

Look at the DB_HOST key. If it is currently 127.0.0.1, try changing the value to localhost

Looks like there is a simple problem with your database connection. I don't know your environment (vagrant homestead/ virtual mashine/ etc.).

First you should check your database configuration. Have a look at these article:

https://laracasts.com/discuss/channels/laravel/sqlstatehy000-2002-connection-refused#best-reply-117961

Your db-host should be set to localhost and your port should be 3306.

Try to clear and cache your config again with php artisan config:cache.

At least you could try to debug your code and check the DB::connection() / DB::connection()->getDatabaseName()