Php Laravel 5-未知数据库

Php Laravel 5-未知数据库,php,mysql,database,laravel,Php,Mysql,Database,Laravel,我正在尝试用laravel 5制作一个登录表单 每次我尝试登录时都会出现错误 Connector.php第55行出现异常:SQLSTATE[42000][1049]未知 数据库“php2project” 但是,数据库仍然存在。 我可以毫无问题地使用“php artisan migrate”,所以我不知道现在为什么会出现这个问题 下面是我的.env文件的外观 APP_ENV=local APP_DEBUG=true APP_KEY=_STACK_ DB_HOST=127.0.0.1 DB_DA

我正在尝试用laravel 5制作一个登录表单

每次我尝试登录时都会出现错误

Connector.php第55行出现异常:SQLSTATE[42000][1049]未知 数据库“php2project”

但是,数据库仍然存在。

我可以毫无问题地使用“php artisan migrate”,所以我不知道现在为什么会出现这个问题

下面是我的.env文件的外观

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
编辑:这是我的配置/数据库信息

'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'   => '',
    ],

],
控制器

<?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');
            }
        }
    }
}

首先检查.evn中是否设置了正确的凭据

如果是,则尝试缓存配置。有时可能会出现问题,因为您在.env中进行了更改,但没有缓存它(仅当您在项目中缓存配置时)


尝试运行
php artisan cache:config
config->database.php中,您的数据库设置为forge,而.env文件中的数据库名称为php2project。确保两个文件中的内容相同,另外,密码在config->database.php中为空,但在.env文件中设置为_STACK_uuu,并确保您的用户名在这两个文件中相同。

您可以发布以下内容:
app/config/database.php
?您正在使用哪个环境?@Daan更新了您通过
php artisan运行此文件的OPAre有机会发球吗?在
service
命令启动后,您是否对
.env
文件进行了任何更改?我看到您正在使用laravel的
auth
您是否可以查看
app/config/auth.php
中的驱动程序是否设置为eloquent或database?如果口才好,你能发布用户模型吗?
@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() !!}