使用 Laravel 6 连接到 Firestore 不工作
Connecting To Firestore Using Laravel 6 Not Working
我一直在尝试使用我的 laravel 6 应用程序将数据插入到 firestore 中,它似乎正在尝试连接到 mysql。
我试图删除我的 .env 文件中的数据库部分:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
但是好像不行。
首先这是我尝试插入时出现的错误:
"message": "SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
这是我的 php 代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Google\Cloud\Firestore\FirestoreClient;
use Google\Cloud\Firestore\FireStoreDocument;
class LogisticsController extends Controller
{
public $firestoreClient;
/**
* __construct initialize firestore client
*
* @return void
*/
public function __construct()
{
$this->firestoreClient = new FirestoreClient([
'projectId' => 'my-project-id',
]);
}
/**
* create a new logistics company
*
* @return
*/
protected function create(Request $request)
{
//get and validate form data
$validatedData = $request->validate([
'company_name' => 'required|unique:company_name|max:255',
'registration_no' => 'required'
]);
$company_name = $request->company_name;
$registration_no = $request->registration_no;
$this->firestoreClient->addDocument('Logistics_Companies', [
'company_name' => $company_name,
'registration_no' => $registration_no,
'created_at' => new FirestoreTimestamp,
'updated_at' => '',
'deleted_at' => ''
]);
}
}
我不知道为什么它会尝试使用 mysql 进行连接。任何人都知道我需要做什么或做错了什么???。
我们非常感谢各种形式的帮助。干杯!!!!
env 文件仅用于覆盖 config/databases.php 文件中定义的默认数据库,如果您不想在该文件中修改此行使用 mysql:
'default' => env('DB_CONNECTION', 'mysql')
但是,由于它正在尝试连接到 mysql 数据库,因此您在项目的某处使用了 Laravel 的 orm (eloquent) 并且需要集成 Firestore在更深层次上进入 Laravel 或避免使用 Eloquent.
我一直在尝试使用我的 laravel 6 应用程序将数据插入到 firestore 中,它似乎正在尝试连接到 mysql。
我试图删除我的 .env 文件中的数据库部分:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
但是好像不行。 首先这是我尝试插入时出现的错误:
"message": "SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
这是我的 php 代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Google\Cloud\Firestore\FirestoreClient;
use Google\Cloud\Firestore\FireStoreDocument;
class LogisticsController extends Controller
{
public $firestoreClient;
/**
* __construct initialize firestore client
*
* @return void
*/
public function __construct()
{
$this->firestoreClient = new FirestoreClient([
'projectId' => 'my-project-id',
]);
}
/**
* create a new logistics company
*
* @return
*/
protected function create(Request $request)
{
//get and validate form data
$validatedData = $request->validate([
'company_name' => 'required|unique:company_name|max:255',
'registration_no' => 'required'
]);
$company_name = $request->company_name;
$registration_no = $request->registration_no;
$this->firestoreClient->addDocument('Logistics_Companies', [
'company_name' => $company_name,
'registration_no' => $registration_no,
'created_at' => new FirestoreTimestamp,
'updated_at' => '',
'deleted_at' => ''
]);
}
}
我不知道为什么它会尝试使用 mysql 进行连接。任何人都知道我需要做什么或做错了什么???。
我们非常感谢各种形式的帮助。干杯!!!!
env 文件仅用于覆盖 config/databases.php 文件中定义的默认数据库,如果您不想在该文件中修改此行使用 mysql:
'default' => env('DB_CONNECTION', 'mysql')
但是,由于它正在尝试连接到 mysql 数据库,因此您在项目的某处使用了 Laravel 的 orm (eloquent) 并且需要集成 Firestore在更深层次上进入 Laravel 或避免使用 Eloquent.