In this chapter, we gonna learn how to create a new Cloud Firestore database and get necessary credentials to connect with a Laravel Project.
First of you have to visit the https://firebase.google.com/ and then click on the "Go to console" on top right of page. Then sign in with your gmail ID.
Once you are in, you would see the list of your projects. One Project consists of one Cloud Firestore and one realtime Database. (We are gonna use Cloud Firestore).
So lets begin by clicking on "Add Project" button.
Enter a proper name for your project.
Then you can enable the google analytics for all kind of reportings.
Then wait for few minutes, it will create a whole new project for you.
Now click on "Continue".
On the home page, you will find many options to get started. On the top left near to side bar, you will find the current project selected in the drop down of all your project. You can switch to any of your project easily.
Now lets quickly move to the Database option from left sidebar. We will cover the Authentication in next upcoming chapters.
Here on the scroll the page, you will find the option for creating "Realtime Database". But we are gonna use the "Cloud Firestore" as it the very much advance version than "Realtime Database" (Here again don't be confused by the name realtime that it provides realtime data and firestore don't. Its not like that. Realtime Database is the older product and Cloud Firestore is latest one and to be used in future with extra functionality).
Now click on the "Create database". Select "Start in test mode". (We will explain how the rules works in Firestore in upcoming chapter and when to move on to Production mode)
Now select the Cloud Firestore Location nearer to you. or you can just keep the default one. But keep in find it cannot be changed later. Now proceed and wait for few minutes will its create a new firestore database for you.
Once your database is ready, you will find four tabs "Data" where our data gets stored in the large tree structure. The second one is "Rules" (will cover this is in upcoming chapter), you don't need to setup this right now. The third one is "Indexes" where all indexes of fields are store (Don't worry whole separate chapter will be there for this).
And the last fourth one is "Usage". Here you can find all kinds of stats made to you database ex: read request for specific period of time.
Now our database is good to go. Now comes the connection part i.e the credentials key or file which will be used to connect our laravel project with this database. So for that you have to open the project settings from setting icon in top left near the Project Overiew text in the left sidebar.
Now once you are in the setting page. You will find many options to do. You can change here the Public facing name which will be used in Email verification template. (Don't worry this will be covered in Authentication chapter). Then scrolling down, you will find the "Your apps" section. Here you get options for the SDK for IOS, Android and Web. Don't be confused with Web part. This is not what we are going to use. This will be generally for Javacript Projects, the frontend side. Now directly come to the Service accounts tab. Here you will find the Firebase Admin SDK tab. This what we are going to use. Don't worry if there is no PHP mentioned. This is because, many features like realtime time sync is not supported for PHP. But don't worry, we can proceed by selecting Node.js.
There is a button to create a new private key "Generate new private key". Just click on it and it will generate a new key in your google cloud console and a json file will be downloaded. Please save it in secure place, because this cannot be regenerated. Don't worry If it is lost, you have to create a new one and you can continue.
That's done. This json file will be used to communicate between Firebase and Laravel (PHP).
Thanks for reading this chapter. Hope you got the understanding of the Firebase setup process and be ready for the upcoming chapters. Let us know in the comment section your doubts or any topic you want to cover in next chapter.
6 Comments
Let us know your doubts here.
ReplyDeleteSo do you think it is better to use JS-Node.js rather than PHP-Laravel for Firebase related projects?
ReplyDeleteWe guess 'yes'. But PHP lovers are PHP lovers. Then gonna make path for every piece of code.
DeleteI have already created a project using real time database in android studio. Can I link the firestore (from laravel) database to rtdb(from android studio) ?
ReplyDeleteHi
DeleteThanks for reaching out us.
The answer is no.
Realtime database is completely separate from Cloud Firestore.
But for your info. You can use Realtime also in your Laravel project.
Hope it helps. Please share.
Hi, if your issue is solved by any other method than the mentioned one please share here, so other people can be benefitted.
DeleteAnd Please follow us, it helps us.