简体   繁体   中英

How to integrate database in Firebase (Cloud Firestore) with Laravel Auth user

I want to check this user is unique before create it using Firestore with Laravel Auth/RegisterController

Cloud Firestore

I can see from your screenshots that you are using kreait/firebase-php (which I like since I'm the maintainer ).

Were you aware that the SDK also has a Laravel Package? You can find it on GitHub at github.com/kreait/laravel-firebase .

With it, you don't need to instantiate the Factory in your controller, but can use Dependency Injection or the app() helper to retrieve the component you need.

Since I believe that the package would be the best solution for your use case, I will continue as if you were using it ) - once configured, you could do use a transaction (as already hinted by @ Renaud Tarnec ) to check for uniqueness:

/** @var \Google\Cloud\Firestore\FirestoreClient $firestore */
$firestore = app('firebase.firestore')->database();

$firestore->runTransaction(function (Transaction $transaction) {
    // ...        
});

In order to make the functionality available to the validator, you should look at creating a custom rule as described on https://laravel.com/docs/validation#custom-validation-rules - this would probably enable you to use it as you envisioned it in your screenshot.

PS: Please consider embedding images directly in your questions, or, even better, include code snippets as text - this would make it easier to grasp the question in its entirety, and enable others to copy-paste parts of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM