{"id":5700,"date":"2021-03-20T12:46:15","date_gmt":"2021-03-20T12:46:15","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5700"},"modified":"2021-03-20T12:46:15","modified_gmt":"2021-03-20T12:46:15","slug":"how-to-create-api-in-laravel","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/","title":{"rendered":"HOW TO CREATE API IN LARAVEL"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong><em>1<sup>st<\/sup> step:-<\/em><\/strong><em> open command prompt and go to <strong>xampp\\htdocs<\/strong> folder and write the code given below in command prompt to create the project<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">Composer create-project \u2013prefer-dist laravel\/laravel admin \u201c5.5.*\u201d<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>2<sup>nd<\/sup> step:-<\/em><\/strong><em>now go to the project folder and make auth. Code is given below<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"has-inline-color has-vivid-red-color\">\u00a0php artisan make:auth<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>3<sup>rd<\/sup> step:-<\/em><\/strong><em> Now install the passport. Write the code given below in command prompt.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0\u00a0<span class=\"has-inline-color has-vivid-red-color\">\u00a0 Composer required laravel\/passport<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>4<sup>th<\/sup> step:-<\/em><\/strong><em>open <strong>phpmyadmin<\/strong> and make a database.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>5<sup>th<\/sup> step:-<\/em><\/strong><em> open .<strong>env file<\/strong> and configure the database.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>6<sup>th<\/sup> step:-<\/em><\/strong><em> Now migrate the database. Write the code given below in the command prompt<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0\u00a0\u00a0\u00a0           <span class=\"has-inline-color has-vivid-red-color\">php artisan migrate<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>7<sup>th<\/sup> step:-<\/em><\/strong><em>Add the code given below in user model.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0\u00a0\u00a0<span class=\"has-inline-color has-vivid-red-color\"> \u00a0\u00a0\u00a0use Laravel\\Passport\\HasApiTokens;<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>8<sup>th<\/sup> step:-<\/em><\/strong><em> Add the code given below in auth service proviser<strong>(C:\\xampp\\htdocs\\ admin\\Providers\\AuthorServiceProvider.php)<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u00a0\u00a0\u00a0\u00a0\u00a0 use Laravel\\Passport\\Passport;<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>9<sup>th<\/sup> step:-<\/em><\/strong><em> Now configure auth.php<strong>(C:\\xampp\\htdocs\\admin\\config\\auth.php)<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Change the driver and provider as given below in api:-<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u2018api\u2019=>[<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u2018driver\u2019=>\u2019passport\u2019,<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u2018provider\u2019=>\u2019users\u2019<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">],<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>10<sup>th<\/sup> step:-<\/em><\/strong><em> Add the code given below in kernel.php. <strong>(C:\\xampp\\htdocs\\ admin\\app\\Http\\Kernal.php)<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">Protected $routeMiddleware=[<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u2018client\u2019_credentials\u2019=>\\Laravel\\Passport\\Http\\Middleware\\CheckClientcredentials::class,<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>11<sup>th<\/sup> step:-<\/em><\/strong><em>Add the code given below in <strong>app.php(config\\app.php)<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\/*<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0\u00a0 <span class=\"has-inline-color has-vivid-red-color\">*Application Service Providers\u2026<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u00a0 *\/<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u00a0\/\/Passport Service provider<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">\u00a0\u00a0\u00a0 Laravel\\Passport\\PassportServiceprovider::class,<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><span class=\"has-inline-color has-vivid-red-color\">];<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>12<sup>th<\/sup> step:-<\/em><\/strong><em> Write the code given below in command prompt.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"has-inline-color has-vivid-red-color\">\u00a0php artisan passport:install<\/span><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/em><strong>Encryption keys generated successfully.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1st step:- open command prompt and go to xampp\\htdocs folder and write the code given below in command prompt to [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5049,156],"tags":[1056,5052,5150],"class_list":["post-5700","post","type-post","status-publish","format-standard","hentry","category-laravel","category-websites","tag-api","tag-laravel","tag-passport"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HOW TO CREATE API IN LARAVEL - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HOW TO CREATE API IN LARAVEL - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"1st step:- open command prompt and go to xampphtdocs folder and write the code given below in command prompt to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-20T12:46:15+00:00\" \/>\n<meta name=\"author\" content=\"shashank K\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shashank K\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/\"},\"author\":{\"name\":\"shashank K\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/c88b513657ea9e9a6cd8a9b3a3bff6f3\"},\"headline\":\"HOW TO CREATE API IN LARAVEL\",\"datePublished\":\"2021-03-20T12:46:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/\"},\"wordCount\":259,\"commentCount\":0,\"keywords\":[\"API\",\"laravel\",\"passport\"],\"articleSection\":[\"Laravel\",\"Websites\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/\",\"name\":\"HOW TO CREATE API IN LARAVEL - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-03-20T12:46:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/c88b513657ea9e9a6cd8a9b3a3bff6f3\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-to-create-api-in-laravel\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HOW TO CREATE API IN LARAVEL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/c88b513657ea9e9a6cd8a9b3a3bff6f3\",\"name\":\"shashank K\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g\",\"caption\":\"shashank K\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/shashank\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HOW TO CREATE API IN LARAVEL - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/","og_locale":"en_US","og_type":"article","og_title":"HOW TO CREATE API IN LARAVEL - scmGalaxy","og_description":"1st step:- open command prompt and go to xampphtdocs folder and write the code given below in command prompt to [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/","og_site_name":"scmGalaxy","article_published_time":"2021-03-20T12:46:15+00:00","author":"shashank K","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shashank K","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/"},"author":{"name":"shashank K","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/c88b513657ea9e9a6cd8a9b3a3bff6f3"},"headline":"HOW TO CREATE API IN LARAVEL","datePublished":"2021-03-20T12:46:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/"},"wordCount":259,"commentCount":0,"keywords":["API","laravel","passport"],"articleSection":["Laravel","Websites"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/","name":"HOW TO CREATE API IN LARAVEL - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-03-20T12:46:15+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/c88b513657ea9e9a6cd8a9b3a3bff6f3"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-to-create-api-in-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"HOW TO CREATE API IN LARAVEL"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/c88b513657ea9e9a6cd8a9b3a3bff6f3","name":"shashank K","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a1d7da7c43d650339f6ab219ed52f462ee8ce994ce0d45b50c0700eead0676a4?s=96&d=mm&r=g","caption":"shashank K"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/shashank\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=5700"}],"version-history":[{"count":3,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5700\/revisions"}],"predecessor-version":[{"id":5710,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5700\/revisions\/5710"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}