{"id":10169,"date":"2021-06-25T10:00:20","date_gmt":"2021-06-25T01:00:20","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=10169"},"modified":"2021-06-24T21:58:57","modified_gmt":"2021-06-24T12:58:57","slug":"laravel-8-push-notification-using-firebase2","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/10169","title":{"rendered":"Laravel 8 Push Notification using Firebase[2]"},"content":{"rendered":"\n<p><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">Here is final part how to do push notification using Firebase.Let&#8217;s start it.<\/font><\/font><\/p>\n\n\n\n<h4>Get Firebase Cloud Messaging (FCM) Server Key<\/h4>\n\n\n\n<p>This step will show how to get FCM key and Firebase web app&#8217;s configuration credentials.<\/p>\n\n\n\n<p>Then firstly go to the Firebase site and we need to create a project.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"484\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebasecreatescreen-1024x484.png\" alt=\"\" class=\"wp-image-10172\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebasecreatescreen-1024x484.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebasecreatescreen.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then add your notification app name for adding Firebase to web app.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"512\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebaseregister1-1024x512.png\" alt=\"\" class=\"wp-image-10174\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebaseregister1-1024x512.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/firebaseregister1.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then copy the Firebase configuration keys, and this will help to connect laravel to Firebase.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"593\" height=\"502\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-13.50.54.png\" alt=\"\" class=\"wp-image-10175\"\/><\/figure>\n\n\n\n<p>Next, go to the project dashboard setting and copy the sever key and paste in HomeController of SERVER_API_KEY variable in sendNotification() function.  Next step create the controller and let&#8217;s add the key.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"310\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-13.56.39-1024x310.png\" alt=\"\" class=\"wp-image-10176\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-13.56.39-1024x310.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-13.56.39.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4>Create Route<\/h4>\n\n\n\n<p><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">We need to do some of routes to store token and send push notification so let&#8217;s add our routes in web.php.<\/font><\/font><\/p>\n\n\n\n<p><strong>routes\/web.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"974\" height=\"473\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-13.30.08.png\" alt=\"\" class=\"wp-image-10171\"\/><\/figure>\n\n\n\n<h4>Create Controller<\/h4>\n\n\n\n<p>Here, we need add saveToken() and sendNotification() method for admin route in HomeController.<\/p>\n\n\n\n<p><strong>app\/Http\/Controllers\/HomeController.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"906\" height=\"200\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.10.42.png\" alt=\"\" class=\"wp-image-10177\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"681\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.11.38-1024x681.png\" alt=\"\" class=\"wp-image-10178\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.11.38-1024x681.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.11.38.png 1059w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then update the <strong>home.blade.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1005\" height=\"694\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.15.47.png\" alt=\"\" class=\"wp-image-10180\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1005\" height=\"575\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.17.19.png\" alt=\"\" class=\"wp-image-10181\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1005\" height=\"583\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.17.39.png\" alt=\"\" class=\"wp-image-10182\"\/><\/figure>\n\n\n\n<p>In the final step, we have to create head over to a public folder and create a new firebase-messaging-sw.js file; this file holds the web push notification configurations.<\/p>\n\n\n\n<p><strong>public\/firebase-messaging-sw.js<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1005\" height=\"721\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.27.20-1.png\" alt=\"\" class=\"wp-image-10185\"\/><\/figure>\n\n\n\n<p>Finally, to see the push notification results we need to execute <strong>php artisan serve<\/strong> command. Next we will do register, signed-in and then click on the allow notification button,  it will generate the device id, also add push notification title and body in the given form.<\/p>\n\n\n\n<p>we will receive notification as like bellow:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"198\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.48.05-1024x198.png\" alt=\"\" class=\"wp-image-10186\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.48.05-1024x198.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/06\/Screen-Shot-2021-06-24-at-14.48.05.png 1264w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>By Ami<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10169\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/10169\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Laravel 8 Push Notification using Firebase[2]\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10169\" data-text=\"Laravel 8 Push Notification using Firebase[2]\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10169\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10169\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Here is final part how to do push notification using Firebase.Let&#8217;s start it. Get Firebase Cloud Messagi [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10169"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=10169"}],"version-history":[{"count":5,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10169\/revisions"}],"predecessor-version":[{"id":10192,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10169\/revisions\/10192"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=10169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=10169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=10169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}