Understanding the laravel 5 framework, studying the documentation .... stuck on the MySQL connection .... wrote everything in the database.php file (as written in the documentation_):

'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', 'forge'), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], 

just created, as in the documentation file UserController.php:

 namespace App\Http\Controllers; use DB; use App\Http\Controllers\Controller; class UserController extends Controller { /** * Показать список всех пользователей приложения. * * @return Response */ public function index() { $users = DB::select('select * from database where active = ?', [1]); return view('user.index', ['users' => $users]); echo $users; } } 

data from the .env file:

 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database DB_USERNAME=bukreev DB_PASSWORD=bukreev 

where else do I need to register?

  • one
    I myself am not a guru lavel, but have you set your database settings yet in the .env file? - newbie
  • one
    I wrote the same thing myself and everything works. Try to display just all users for verification, without additional conditions. Well, if I wrote everything correctly in the .env file, then try to write forge in database.php instead of users and root (although I doubt that this affects something) - newbie
  • one
    First, you need to call your controller in the routing. With such a link - such a method with such a controller. Secondly, if your database is really called a database, and the user assigned to it is bukreev, then why did you write users with the root user in the very beginning? - newbie
  • one
    I wrote everything in the database.php file (as written in the documentation_): - this is not necessary if you have registered the data in .env and vice versa. I advise you to write everything in .env - Oleg Shleif
  • one
    web.php, advice: see the documentation. Everything is briefly described ... (Route :: get ('user / profile', 'UserController @ showProfile');) - Oleg Shleif

0