我正在Laracasts中从头开始关注Laravel 5系列,具体来说,我是“获取数据”课程。
我创建了database.sqlite文件,我从修补程序中添加了一些数据,并且能够在控制台中检索它们。然后,我尝试复制视频的内容。
我的名片控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
class CardsController extends Controller
{
public function index()
{
$cards = \DB::table('cards')->get();
return view('cards.index', compact('cards'));
}
}
但是,当我尝试加载/ cards路由时,我有以下错误
InvalidArgumentException in SQLiteConnector.php line 34:
Database (homestead) does not exist.
这是我的env
文件
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:P3ZgRMRkb2e8+x7S9rDLLB+bKJdR5Unpj8zXBUIHIZE=
APP_URL=http://localhost
DB_CONNECTION=sqlite
DB_FILE=database.sqlite
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
答案 0 :(得分:2)
在您的错误中引用的那一行下面是:
// Here we'll verify that the SQLite database exists before going any further
// as the developer probably wants to know if the database exists and this
// SQLite driver will not throw any exception if it does not by default.
if ($path === false) {
throw new InvalidArgumentException("Database (${config['database']}) does not exist.");
}
查看方法上方的注释,似乎您的路径未正确设置。我相信正确的环境变量应该是:
DB_DATABASE=database/database.sqlite
而不是
DB_FILE=database/database.sqlite
如果没有,请检查您的config/database.php
文件,然后查找此部分:
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')), // this line!
'prefix' => '',
],
答案 1 :(得分:0)
我也注意到了(至少在Mac上的Laravel版本5.2.29中)路径必须是绝对路径。奇怪的是,对于运行迁移,相对路径将起作用,但在此之后尝试访问数据库时应用程序失败