Laravel 5 - Unknown Database

I am trying to create a login form in laravel 5.

Every time I try to log in, I get an error

PDOException in line Connector.php 55: SQLSTATE [42000] [1049] Unknown database 'php2project'

However, the database does exist. enter image description here

I could use "php artisan migrate" without any problems, so I have no idea why I have this problem right now.

here what my .env file looks like

APP_ENV=local
APP_DEBUG=true
APP_KEY=_STACK_

DB_HOST=127.0.0.1
DB_DATABASE=php2project
DB_USERNAME=root
DB_PASSWORD=_STACK_

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

EDIT: here is my configuration / database information

'default' => env('DB_CONNECTION', 'mysql'),

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/

'connections' => [

    'sqlite' => [
        'driver'   => 'sqlite',
        'database' => database_path('database.sqlite'),
        'prefix'   => '',
    ],

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

    'pgsql' => [
        'driver'   => 'pgsql',
        'host'     => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
        'schema'   => 'public',
    ],

    'sqlsrv' => [
        'driver'   => 'sqlsrv',
        'host'     => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
    ],

],

controller

<?php
namespace App\Http\Controllers;
use View;
use Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;

class LogInController extends Controller 
{
    public function showLogin()
    {
        return View::make('login.login');
    }

    public function doLogin()
    {
        // validate
        $rules = array(
            'email'    => 'required|email',
            'password' => 'required|alphaNum|min:3'
        );
        // run the validation rules on the inputs from the form
        $validator = Validator::make(Input::all(), $rules);

        // if the validator fails, redirect back to the form
        if ($validator->fails()) {
            return Redirect::to('login')
                ->withErrors($validator)
                ->withInput(Input::except('password'));
        } else {
            // create our user data for the authentication
            $userdata = array(
                'email'     => Input::get('email'),
                'password'  => Input::get('password')
            );
            // attempt to do the login
            if (Auth::attempt($userdata)) {

                // validation successful!
                // redirect them to the secure section or whatever
                // return Redirect::to('secure');
                // for now we'll just echo success (even though echoing in a controller is bad)
                echo 'SUCCESS!';

            } else {        

                // validation not successful
                return Redirect::to('login');
            }
        }
    }
}

view

@extends('layouts.master')
@section('title', 'Login')
@section('content')

{!! Form::open(array('url' => 'login')) !!}
    <h1>Login</h1>
    <p>
        {!! $errors->first('email') !!}
        {!! $errors->first('password') !!}
    </p>

    <p>
        {!! Form::label('email', 'Email Address') !!}
        {!! Form::text('email', Input::old('email'), array('placeholder' => 'john@snow.com')) !!}
    </p>

    <p>
        {!! Form::label('password', 'Password') !!}
        {!! Form::password('password') !!}
    </p>

    <p>{!! Form::submit('Submit!') !!}</p>
{!! Form::close() !!}
+4
source share
2 answers

First check if the correct credentials are set to .evn

, . , .env, ( ).

php artisan cache:config

+1

, ​​ forge config- > database.php, .env - php2project. , , config- > database.php, _STACK_ .env , , .

-2

Source: https://habr.com/ru/post/1611279/


All Articles