Sentry と Composer をインストールしたので、Illuminate Database もインストールされました。インストールは成功しました。Sentry のドキュメントのすべてを実行しました。簡単なコードでデータベースにユーザーを追加しようとしています。ただし、次のエラーメッセージが表示されます。
Fatal error: Call to a member function connection() on a non-object in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\ilhan\vendor\illuminate\database\Illuminate\Database\Eloquent\Model.php on line 2472
私のコードは次のとおりです。
<?php
include_once "vendor/autoload.php";
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'ilhantestdb',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]);
use Cartalyst\Sentry\Sentry as Sentry;
try
{
$user = new Sentry;
// Create the user
$user->createUser(array(
'email' => 'john.doe@example.com',
'password' => 'test',
'activated' => true,
));
// Find the group using the group id
$adminGroup = Sentry::findGroupById(1);
// Assign the group to the user
$user->addGroup($adminGroup);
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
{
echo 'Login field is required.';
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
{
echo 'Password field is required.';
}
catch (Cartalyst\Sentry\Users\UserExistsException $e)
{
echo 'User with this login already exists.';
}
catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
echo 'Group was not found.';
}
これをデバッグする方法もわかりません。また、Illuminate には Sentry が付属しているので、Sentry は Illuminate を処理する方法をコーディングする必要があるため、多くの構成は必要ないと考えました。ドキュメントが貧弱で、このエラーの対処方法がわかりませんでした。