CRUD in Laravel PHP Firebase SDK from Scratch. Installation to CRUD with Realtime Firebase Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to my channel so guys in this video we are going to learn new topic with the laravel and firebase for php okay so guys we'll be using our firebase with the php and laravel application so guys let's get started so we are going to do a crud application using laravel 6 which is available over here so let's go to our firebase php documentation where you'll find installation under overview laravel so let's click on this control click you'll move to github repository and let's go below guys here the firebase for laravel okay so installation part laravel thing right so you need to install this layerable firebase in your laravel application so before getting started you need to install this so what version you're going to install laravel so currently the version is eight but our firebase php for laravel it provides that is six guys so seven and eight this package is not available few things so let's begin with it guys let's go check out with laravel 6.x installation installing laravel move below here is a code guys so let's copy this command and i want to create the project over here so let's open the git batch guys and now copy this get back to your git bash paste and rename this as laravel 6 fire base okay hit enter so let's let's wait until it gets installed so it's our application installed successfully let's close this terminal and here is our level 6 firebase and open with git bash and open with code guys so let's move to our command prompt where php artisan serve hit enter so it's started let's close this go to url let's type localhost 8000 let's keep at first perfect guys so this is our laravel application so under resource views on the welcome blade we have the output where laravel plus firebase for php okay save cool guys so now we are going to get started with firebase installation firebase php installation so let's move to github repository and installation part first thing let's copy this get back to your application start your terminal and paste the code hit enter so it's installing so let's let's wait for the complete installation perfect yes so it has been successfully installed let's kill this terminal and yup guys let's get back next step need to go to your inside your laravel so you need to go to app.php under config folder and copy this copy let's go to config app.php move below so this is the providers and paste that give comma all set let's close this and again this is for lumen not required and now guys you need to do the configuration so first let us publish this copy and ctrl tilde symbol backtick to open your terminal guys and hit enter perfect so you can find that firebase.php file also over here so yep let's close this and now let's get back let us set the credentials so go to your dot env file so copy dot env file and after database only i want to paste that so firebase credential and then your database url so paste it all set guys let's give it double quotes so guys to get the firebase credential and database url you need to create a project first so let's get started with it so let's move to our firebase console and with your email id just log in and create a project so let's add a project my project name will be laravel firebase tutorial okay hit enter so you are going to next step let's continue this and the service account let's select default account for firebase create a project creating a project guys so let's wait for this perfect so it's done guys and now let's continue okay so here is our firebase laravel firebase tutorial so guys now you need to go to your settings over here project settings and generate the which credentials so you need to move over your service account and we are using firebase admin sdk and just create a service account so let's click on create perfect so it's created guys and now you can generate a new private key let's click download this generated key and it's over here guys now let's take this so let's move to downloads windows e and this is the code guys so let's control x and paste into your firebase application directly so this is my root directory where i have pasted this perfect guys so let's copy okay control c get back to your application where you can find this over here okay and paste it over here perfect done and then database url we are missing so let's get back and yes guys so let's move to our build inside that build we are going to work with real time database so in for this video we will be seeing learning about this authentication firestore database everything okay so click on real-time database and create database guys done so i'm going to select united state only next let's select with this start in test mode and enable it perfect so our database is created guys and this is our database link so let's copy this and done let's get back to our application and paste it all set guys so now let's get back if you change anything in your dot env file you need to restart your application otherwise error will be given so guys we have successfully done how to install our laravel and firebase in php with your database connection and creating the credential of your service account so guys let's see how to insert the data in laravel firebase and now guys in this will be learning how to set up a template for a laravel application so guys now like a navbar we will design and one simple card with the contact form okay so guys let's continue to build this so let's move to our application let's close let's move to routes web.php and route colon colon get function where you are going to create with the contacts where you are going to create one controller so that will be the contact controller colon colon class where you'll call index page okay index function let's comment this and create one controller guys first so php artisan make colon controller i want this controller to be created inside firebase folder forward slash contact controller okay hit enter so you can go to app http controller you'll find firebase folder contact controller perfect so now guys let's create a function public function with the name index function and yep let's kill this terminal return view where you will tell inside my firebase folder dot contact folder dot index page okay so let's move to resource views inside this views let's create a firebase folder and one more folder with the name contact done and inside this contact folder i want to create a index.blade.php file perfect so inside this firebase folder not under contacts we are going to firebase folder and create a file with the name app.blade.php all set now guys you need to set up the files so first let's go to welcome which is provided by the laravel let's move top and just copy few things let's copy this paste get back move below and this is your body tag guys perfect so close the body now guys you can just p by 3 and above this you can use include function to include the navbar so let's create one inc folder inside that navbar.blade.php file okay so let's create that inside the firebase folder so this is my firebase folder inside this firebase folder i want a folder with the name inc and this is the never dot blade.php so guys now let's move to our app so this nubber is called perfect so now over here we need to yield it yield that will be our content done so we are going to use bootstrap 5 for the designing purpose so let's go to get bootstrap.com click on docs let's move below this is css link copy it and paste all set let's remove this extra thing and the bundle file under js copy it paste and let's remove this we do not required it all set guys so now let's create one navbar navbar let's copy this number go to your file nav bar paste we don't require a few things so let's remove it and all set guys and instead of bg light i'll give primary save level firebase and this is your link so we will tell this will be a contact contacts list and create the url guys over here url which will be your contacts the route we have created okay save it let's close this file now let's get back to our index page let's extend that extends which which comes under firebase folder dot app file and the section is content okay so this content you need to just call that cool all set guys and let's see the output so can get over here give contacts okay route is not called why we have commented it let's uncomment and import this class guys so just import the class of it and you can find it out perfect so let's make this a white color guys go to your navbar dark and make this to container that's it refresh perfect so click on contact list you will be over here so same thing if you require on this home page just need to add this code so let's take this go to your welcome blade and remove paste remove this body tag and just end the section guys paste all set so you can find it contacts list perfect so now let's get back close this welcome and now guys you can create one container row column md12 where card card header inside this h4 tag you are going to tell contact list so card body here will be your all the contact data so we will see in further videos next video will be learning how to insert the data so at that time i will show you add contact add a class guys over here button button small button primary okay so create a href url where you will tell add contact perfect let's float end so save and see the output refresh under contact perfect guys so when you click on this add contact that should go and insert the data so we will see in next video so guys we have successfully learned how to set up a laravel file that is we have learned about the laravel templating okay how to insert the data into our firebase real-time database okay so we are going to use level application where with the help of firebase admin sdk for php will be inserting the data in our real-time database so guys to insert the data first we need to create a table so this is my database let's create one table so let's create contacts and just give a a value over there and let's remove this we don't need the value just keep it null guys perfect so this is our contacts table for example reference table okay so now guys let's begin with our contact list so click on it on this add contact when you click a url is created guys so let's create this let's get back so first let's move to index this was our add contact button with the url add contact so let's copy this and create a route for this guys so route colon colon get function and go to the controller so we are going to use the same controller let's copy and paste go to create function let's go to the contact controller create a function with the name public function create function open and close return view inside the firebase folder contact folder create blade file so let's move resource views firebase contact inside this file create.blade.php file perfect so now guys let's get back to index file copy the same code and paste and let's make some changes over here so instead of contact list add contact and contact and make this button to danger design and keep a back back button name and make this as column six perfect guys so inside this our form will be so start with the form where you are going to create an action url where we will tell same url okay so add contact we are going to store the data with the same url method is equal to post and generate the csrf token done so guys we need a input fields now so let me just design with that form hyphen group dot margin bottom three and input dot form hyphen control where the column field name using name attribute first underscore name let's give a label over here you will tell let's remove this for we do not require first name perfect so copy paste paste paste we required only four inputs last name and phone number and one email address so same way you are going to give last name make this to small t this will be your phone and this will be your email perfect and simple guys one button remove this button [Music] save design the class primary and the button type will be the submit all set so let's see the output refresh cool so now guys let's insert the data so first step we need data like when we click on the submit button it goes to this url with the post method okay so let's go to web.php and create a route using post method where add contact comma the same controller will move on so let's go to this controller and create a store function so let's go to this controller guys at public function with the name store function all set and now guys you need to insert the data over here so before that let's get back to our real-time database so first let's initialize the real-time database component guys for that in level you can use over here you can see that it's providing laravel you can use this so let's copy this and and paste all set let's copy this and paste it perfect guys so now you are getting the database connection okay if you have given your dot env file connections right so which you can see this in part one let's close so second step now let's move to saving data let me find that push function so you can see that guys over here okay so let's copy this method copy and use it over here so your data will be inside this array like fname this will be our database column field name okay and the request so get the request dollar the request which you get from your form okay so these form request you are going to get from request of your input field name okay so first name copy and paste so same way guys you need to call for all the fields which will be the last name and this will call the last name phone and email perfect so same way you are going to keep for this also phone email done guys and now this database so instead of this database i need to copy this and paste that paste it and now what is this this is your get reference so we'll tell reference underscore the table name okay single quotes we are going to paste that table name what we have created its contacts okay so contacts take this table name and paste it done okay so guys there is one change over here i don't want to repeat this in everything like insert edit update i don't want to call this table so let's make this to global thing okay so same way as you can just copy this and change this table name over here and make this to the table name contacts all set perfect so now you can just call this dollar this of table name okay done and now once the data is post you can check this in if condition if the data is success you are going to return and redirect redirect back with the message status where you will show that contact added successfully and you are going to redirect back wait i want to redirect back to this contact page okay so this page so let's get back contact page else we are going to return at the same page okay contact not added okay and to view the status let's move to index blade file user if condition session where status and f where you can use h4 session of status okay so let's keep this in a design alert alert connect okay save it get back and now guys let's save the data so let's check the code once again in our contact controller so everything is fine now okay let's get back let's insert with the data with prakash for number okay email way that gmail.com click save and boom so contact added successfully let's see in our firebase perfect guys so you can see that with prakash and phone number and its email ids added so let's add one more data so prakash some random digit phone number um gmail.com click on save perfect so we are getting the message and you can see guys second data also has come cool so now guys we have successfully seen that how to insert the data into a real-time database using firebase php in laravel so guys in this let's continue how to fetch this firebase real-time database data in our laravel application how to fetch the data from our real-time database and show in our laravel application using firebase php so guys let's get started with it so first let's move to our laravel application at the web route so web.php and this is our page guys so at this route i want the data to be shown over here okay so let's go to this page let's move to this route at index function so at this index function you can view this index file done and this is the data guys so now over here let's design a table border table head table row table heading which will be one id and the first name and last name email and phone number okay so phone and one is for edit one is for delete perfect so guys now table body table row table data okay so let's use for else else okay control x and how much three three six one seven column is there guys so let's use no record found add a call span that is seven guys that's it and now here your id will be so dollar key of items so what collections of data you are going to get that is nothing but your let's go to contact controller at this index function we need to call that so how will you get the data so for that guys you need to move to your real-time database at the documentation retrieve data so let's copy this copy and paste done guys so this database we have already initialized which we have seen while inserting the data so let's download this of database get reference and from this what reference you are going to get your table so my table is here so dollar this table name my table name is contact okay so this contact table name i'll show in my real time database so this is the contacts table guys done and now you are getting the table so i want to get the values from this table so what value i mean to say this values so these are your data guys so you need to get these data so for that there is one get value function so you can see over here also and you can follow here also okay so let's copy this guys copy and paste at this last get value done so this is this is your contacts data now copy and send it inside of compact function contacts go to your index file okay so this is my index file at this place of collection you need to paste contacts as key where this key all will show your normal auto incremented id so these are your keys guys so inside these keys you have your data okay so that values inside this keys you will get so this item let's take this item and print inside the curly brace dollar item of your f name okay so y f name the path you can see f name l name phone and email okay so these column field names you need to call it copy and paste l name next is email and next is phone and then guys you need to edit and delete so let's copy and paste and give a a tag with edit design this button guys button button small button success copy and paste make this to danger which this will be a delete button and one thing we forgot that is your key so yep done let's see the output guys refresh cool so guys you can see the id and these are the data so we do not require to show this id you can just remove this and give dollar i so initialize it php and php where dollar i is equal to one we will start it that's it save refresh cool guys so you can see one showing one one only needs to give plus plus over here that will be auto incremented perfect so one and two let's add one more data like narendra gmail.com save okay so you can see that third data is narendra modi narendra gmail.com with the phone number perfect guys so guys we have seen that how to fetch the data from our real-time database in laravel okay where now guys we are going to edit and update the data in our real time database guys so let's get started so first let's move to this our contacts where we have shown this data at this table so let's move to our application and at this index file we have this edit button guys which is over here available okay so now let's create a path where url open function edit contact slash give dot dollar key so this key we have getting from this contact okay so this key means this will throw your this keys okay this is your child's so those data you will get over here and yup guys so let's check it over here refresh and click on edit perfect so edit contact with the key now let's create a route guys copy go to your web.php create a route using get method where edit contact forward slash open and close your id and move to your controller so let's move to the same controller that is contact controller and now guys let's move to the edit function so let's go to contact controller and create a edit function move below so public function with the edit function function where you are getting dollar id so this dollar id you are getting from your parameter okay let's get back written view where inside my firebase folder contact folder i want to edit blade file okay so let's go resource views firebase contact inside this contact i need a edit.blade.php file and the form seam form will be using it so which form i'll show you at this so we are going to use this add contact form for editing the form okay so let's get back ctrl a ctrl c and paste it that let's change few things edit contact and this is the back button so let's keep the same thing and update contact okay guys see the output guys first so get back let's click on edit you can see edit contact perfect so now let's get the data of this key or id so let's move to our controller and we will tell dollar key is equal to your id so this id which you are getting from it it's a key and you need to get the data from where your database so let's go to our documentation and you can so let's check below okay so we are going to get something like this with the child keys so let's use this only guys let's click on retrieving data retrieving data let's copy this paste it here and the reference is our table name so dollar this of table name so this is defined at the top guys under our constructor method and the database you have defined as this dollar this database so let's give this database connected and your table name is also connected guys and now you need to get your child keys so your keys so what is this key called as child key so here returns your relative path so let's use this get child function get child function let's send this key and then guys after checking all this id we need to get the values so you can get the value also by using this get value function perfect so now this is your edit data where let's pass this in if condition if it is present like that data then you will send this data in a compact function take this edit data and send it else if id is wrong any key child is someone have missed with that so at that case you need to tell contact id not found that's it so guys now let's take this data and go to edit blade file let's move and over here in the input fields we are going to call that value attribute and send that dollar edit data of what your f name if name copy this paste paste paste done let's make it a name and next post phone and this is email so these fields are nothing but your database column fields okay so you can find it over here now let's refresh perfect guys so now let's change and save to update when we update the data we need to update with this id so first change this name to update and the route update contact dot dollar key so this key from where you will get you'll get from your controller so let's send that in compact function so this dollar key send that done guys so now let's see refresh so now let's click on update you'll find that update with the id okay so now let's create a route guys and submit this data so copy this go to your web dot php create a route colon colon using put method we are going to update the data so update contact where you are sending the id that is your key at this controller so let's copy this controller move to the update function so you're using put method right so you need to add that at method single quote put put i have used capital save let's get back create a update function in your contact controller public function update where you are going to get all the request so request means your input field requests so request and you are getting a id also from your parameter url okay so this id let's go to this update and now guys let's update the data so let's get back to our documentation where under this saving data you'll find update specific fields okay so you can use this where is it here update data okay so these are your updates with the url also you can update and okay so let's use it guys let me just type update function okay so we are over here let's get this data copy and paste it all set so first set up your database guys so this dot database and your table name dollar this of your table name okay so this database and table name you get from your constructor method okay table name and database perfect so now inside this update data we need to send all the data so let me just copy from the post paste it so these earlier all all are your requests this form request okay first name last name phone email from the edit method you are going to get using post method okay so this install of post data give update data and send here update data perfect and now guys you need to update with the specific field so for that case you are going to use concatenate over here and give forward slash dollar key okay so this dollar key you will get from this dollar id okay so this dollar ad you are getting it and storing into key and sending that table so this will be my contacts table forward slash with the key perfect now you can tell response of updated is equal to check in if condition if this data is successfully stored updated then you can show the message contact updated successfully okay else you can just show contact not updated successfully perfect guys so now let's test it guys let's refresh once so from with prakash i'm going to wait prakash n and change this phone number to six five five five and four four let's update and contact updated successfully so data is updated successfully over here as you can see that phone number is updated and initial is also added okay so let's see database perfect so phone number is updated and data also is added let's edit this third data so narendra gowda we will update this update perfect some from modi to how to download and update the data in our real time database of firebase php and now guys in this will be deleting the data so we are going to delete a specific record from our real time database using php firebase so guys let's get started so first let's move to this table at this delete button let's get back and here is the delete button guys and this is our a tag and we are going to create a route a url function where you will tell delete contact okay and give forward slash dot dollar key so this key means your that id so your child id is from your contact table okay so let me just show you a demo over here guys refresh let's click on delete delete contact with the id okay let's get back and let's copy this route url and create creator route guys so we are going to delete with the get method so one method we will use now using get method to delete the data forward slash id your parameter and go to your controller so let's copy the controller guys paste use this draw function inside your contact controller public function where function name destroy function and yep guys so first let's get back to our documentation and here delete data here is the function guys so let's copy this so dollar this of database we have given this in our construct method so let me show you and the table name we have directly assigned it so let's take this table name so dollar table name so let's pass this dollar this of table name dot dot give forward slash and give dollar key so this key is nothing but your parameter which you send from id so let's get this id from your desktop function and this desktop function is passing the id with your route so this id okay so that id we are getting and keeping in a key and creating contact forward slash your key okay and remove this data perfect so now you can tell dollar deleted data is equal to copy check in if condition else delete data let me copy this paste contact deleted successfully and you can just paste this until contact not deleted and let's go back to contacts page done guys so let's see the output let's get back refresh and let's add one dummy data dummy dummy some random digit phone number email save okay contacts added here is the dummy data let's see in this the fourth one which is dummy okay let's delete this guys delete perfect so contact deleted successfully let's see now firebase perfect guys so that fourth data is not there done and this was one method guys you can just create in another method also using delete function let me just comment this and minimize this sidebar just add a form tag and create one submit button use the same class this will be the delete button type is equal to submit method is equal to post and the same url you're going to take it so no changes from the url and here you're going to send if you're sending a request means you have to send a form i mean csrf token and the method you are going to use is delete method okay so this was the thing guys which i wanted to explain to create the delete route so let's copy and paste we are not going to use get method so let's comment that and we are going to use delete method okay so you are using delete and you are not going to change anything in this and neither in your destroy function so just changes is happening over here okay under web.php save guys and now let's refresh perfect so now let's add one more data like user one so dummy datas let's click to save ok so user1 has come over here let's click to delete him and perfect so you can see contact deleted successfully and the data is deleted guys so guys we have successfully done how to delete the data from our real-time database in php firebase laravel so guys in this we are going to learn how to get the total number of records entered or inserted entire inside our real-time database and show them okay so guys let's get started with it so first let's go to this contact list over here let's okay so let's type total colon and just leave it blank refresh so we will show that number of data is inserted over here is three okay so guys for that you need to go to this controller first let's move to web this is your contact at the controller index function here it is okay so the number of data inserted inside this table we need to get so let's tell total contacts is equal to to get that data you need to go to your real-time documentation firebase where we'll tell database retrieving it okay let's use the same thing guys let's get back paste on comment and database configuration let's give the same way and then reference is dollar table name so let's give dollar this table name and to get the total number of record you need to use this get snapshot paste why we are using this get snapshot i'll show you okay so here number of children copy this so this will check of this snapshot okay children function so this is total contacts let's send that in a compact variable i mean compact function so let's copy this and go back to your blade file open and close curly brace just paste that total contacts dollar total contacts save now refresh perfect so you can see guys three data is there let's add one more data called varun govern so some data overnight gmail.com save and you can see the data is four guys so four record is shown over here total is four so guys in this video that's it and let's continue in next video with the new topic of php laravel firebase so guys thank you for watching this video please subscribe like and share
Info
Channel: Funda Coder
Views: 802
Rating: undefined out of 5
Keywords: fundaofwebit, funda coder, laravel php firebase curd app, php firebase laravel crud, laravel firebase php crud step by step, php firebase laravel crud application, how to insert data in realtime database in laravel firebase, insert data in laravel firebase, fetch data in laravel firebase, insert data php firebase in laravel, laravel firebase crash course, install firebase in laravel, firebase php installation in laravel, firebase admin sdk in php laravel
Id: 1ZqzCHS9JO0
Channel Id: undefined
Length: 57min 59sec (3479 seconds)
Published: Sat Aug 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.