{"id":514,"date":"2024-04-11T09:26:01","date_gmt":"2024-04-11T09:26:01","guid":{"rendered":"https:\/\/blog.200oksolutions.com\/?p=514"},"modified":"2025-12-04T07:44:09","modified_gmt":"2025-12-04T07:44:09","slug":"custom-laravel-package-development","status":"publish","type":"post","link":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/","title":{"rendered":"Custom Laravel Package Development"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Requirements :<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Laravel v 5.5 or above is required.<\/li>\n\n\n\n<li>Composer is installed on your system. You may get Composer&nbsp;<a href=\"https:\/\/getcomposer.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>&nbsp;if you don\u2019t already have it.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install the Laravel App<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first step is to construct a Laravel website. We\u2019ll use Composer to set it up. Check out the official\u00a0<a href=\"https:\/\/laravel.com\/docs\/5.6\/installation\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel documentation<\/a>\u00a0for more installation options.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-76d4788589d8be7f68fe0be17945700c\"><code>$ composer create-project laravel\/laravel custom-package --prefer-dist\n$ cd custom-package\t\t\n$ php artisan key:generate<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Project Structure<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP Composer is used to update dependencies and publish packages. A Composer is a tool for dependency management in PHP.<\/li>\n\n\n\n<li>Before creating the composer.json file, create the below folders inside your Laravel project<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-5a873d5de7a92ae0c60d6871e90e5bfc\"><code>\u251c\u2500\u2500 packages\n\u2502   \u2514\u2500\u2500 test\n\u2502       \u2514\u2500\u2500 custom_package\n\u2502           \u251c\u2500\u2500 src\t<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create Composer File<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the below command to generate composer.json<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-5c1bf002b0cfa24b877e3adfb010d5e9\"><code>$ composer init<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The composer.json file should now look like this.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-53469e23277d0d36528d6a7d9f0eb303\"><code>{\n   \"name\": \"test.php\/custom_package\",\n    \"description\": \"custom package\",\n    \"authors\": &#91;{\n       \"name\": \"customTest\"\n  }],\n    \"require\": {}\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let us begin with autoloading the newly created package via the autoload block and add that code in composer.json.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-c593b2d8c35dc7dc4178b9d543e60302\"><code>\"autoload\": {\n    \"psr-4\": {\n     \t\"test\\\\custom_package\\\\\": \"src\/\"\n    }\n }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Adding Routes.php File<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This will be accomplished by creating new routes.php in the package src dictionary, you can simply copy and paste the below-shown also.<\/li>\n\n\n\n<li>After this include the routes.php file inside the boot() method of the service provider\u2019s boot method.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-ef09b73d3b1b4ddb5c1a100b549b40c1\"><code>Route::get('cus', function(){\n        echo 'Hello From Custom Package!';\n    });\n public function boot(){\n\t  include __DIR__.'\/routes.php';\n    }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Add Package Service Provider<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>At the root of our app, let\u2019s create our ServiceProvider with an artisan command via the command line.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-928db0e0aaf3daec9867f5747b778ccf\"><code>$ php artisan make:provider CustomServiceProvide<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After its process is completed, you\u2019ll find a new file located at:<\/li>\n\n\n\n<li>app\/Providers\/CustomServiceProvider.php<\/li>\n\n\n\n<li>The next step will include moving this file into the package folder, the location will be:<\/li>\n\n\n\n<li>packages\/test\/custom_package\/src\/CustomServiceProvider.php<\/li>\n\n\n\n<li>Don\u2019t miss out on changing your namespace to be:<\/li>\n\n\n\n<li>Next, the last step of this pointer will be the addition of a new service provider in the large bracket \u2013 [] array mentioned in config\/app.php:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-c890a5d448651d6c8ac2ac9f0c860bf1\"><code>providers' =&gt; &#91;\n        App\\Providers\\RouteServiceProvider::class,\n        App\\packages\\test\\custom_package\\src\\CustomServiceProvider::class,\n    ],<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Create a Package controller<\/h3>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-dd5a812ed954f0413af05473624f2d32\"><code>$ php artisan make:controller CustomController<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After its process is completed, you\u2019ll find a new file located at:<\/li>\n\n\n\n<li>app\/Http\/Controllers\/CustomController.php<\/li>\n\n\n\n<li>The next step will include moving this file into the package folder, The location will be:<\/li>\n\n\n\n<li>packages\/test\/custom_package\/src\/CustomController.php<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-b035ac85a288fca7233c7239267c8721\"><code>&lt;?php\nnamespace App\\Package\\test\\custom_package\\src;\nuse App\\Http\\Controllers\\Controller;\nclass CustomController extends Controller\n{\n   public function add($a, $b){\n     echo $a + $b;\n    }\t\n    public function subtract($a, $b){\n    echo $a - $b;\n    }\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Now that we have created our controller, we will need to register it. Inside our Service Provider class in the register() method.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-b15b440b627bd1dc2cc3f50fb6aff6e1\"><code>public function register(){\n    $this-&gt;app-&gt;make('packages\\test\\custom_package\\src\\CustomController');\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Finally, let\u2019s add a few more routes to our routes.php file<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-93e82ecea45038b8c9e332a02a72706f\"><code>Route::get('add\/{a}\/{b}',\n'packages\\test\\custom_package\\src\\CustomController@add');\nRoute::get('subtract\/{a}\/{b}',\n'packages\\test\\custom_package\\src\\CustomController@subtract');<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-aab851b8c1cec5dd04dd188586ac1323\"><code>$ php artisan serve<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Then, if we navigate to\u00a0http:\/\/127.0.0.1:8000\/add\/4\/4\u00a0and<br>http:\/127.0.0.1:8000\/\/subtract\/8\/4\u00a0We end up with the following results!<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"319\" height=\"117\" src=\"https:\/\/blog.200oksolutions.com\/wp-content\/uploads\/2024\/04\/output-1.png\" alt=\"\" class=\"wp-image-519\" style=\"width:354px;height:auto\" srcset=\"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/output-1.png 319w, https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/output-1-300x110.png 300w\" sizes=\"(max-width: 319px) 100vw, 319px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"338\" height=\"139\" src=\"https:\/\/blog.200oksolutions.com\/wp-content\/uploads\/2024\/04\/output-2.png\" alt=\"\" class=\"wp-image-520\" style=\"width:350px;height:auto\" srcset=\"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/output-2.png 338w, https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/output-2-300x123.png 300w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/figure>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Requirements : Step 1: Install the Laravel App Step 2: Project Structure Step 3: Create Composer File&hellip;<\/p>\n","protected":false},"author":5,"featured_media":517,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,1],"tags":[97,95,29,30],"class_list":["post-514","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-php","tag-composer-packages","tag-custom-package-development","tag-laravel-development","tag-php-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Laravel Package Development | Laravel Website Development<\/title>\n<meta name=\"description\" content=\"Custom Laravel package or to start from scratch? Follow these six easy steps, read this article, and learn how to create a Laravel package.\" \/>\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.200oksolutions.com\/blog\/custom-laravel-package-development\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel Package Development | Laravel Website Development\" \/>\n<meta property=\"og:description\" content=\"Custom Laravel package or to start from scratch? Follow these six easy steps, read this article, and learn how to create a Laravel package.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Development, Software, and App Blog | 200OK Solutions\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-11T09:26:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-04T07:44:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png\" \/>\n\t<meta property=\"og:image:width\" content=\"728\" \/>\n\t<meta property=\"og:image:height\" content=\"311\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Piyush Solanki\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Piyush Solanki\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Laravel Package Development | Laravel Website Development","description":"Custom Laravel package or to start from scratch? Follow these six easy steps, read this article, and learn how to create a Laravel package.","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.200oksolutions.com\/blog\/custom-laravel-package-development\/","og_locale":"en_US","og_type":"article","og_title":"Laravel Package Development | Laravel Website Development","og_description":"Custom Laravel package or to start from scratch? Follow these six easy steps, read this article, and learn how to create a Laravel package.","og_url":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/","og_site_name":"Web Development, Software, and App Blog | 200OK Solutions","article_published_time":"2024-04-11T09:26:01+00:00","article_modified_time":"2025-12-04T07:44:09+00:00","og_image":[{"width":728,"height":311,"url":"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","type":"image\/png"}],"author":"Piyush Solanki","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Piyush Solanki","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#article","isPartOf":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/"},"author":{"name":"Piyush Solanki","@id":"https:\/\/www.200oksolutions.com\/blog\/#\/schema\/person\/e07f6b8e3c9a90ce7b3b09427d26155e"},"headline":"Custom Laravel Package Development","datePublished":"2024-04-11T09:26:01+00:00","dateModified":"2025-12-04T07:44:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/"},"wordCount":384,"commentCount":0,"publisher":{"@id":"https:\/\/www.200oksolutions.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#primaryimage"},"thumbnailUrl":"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","keywords":["Composer Packages","Custom Package Development","Laravel Development","PHP Development"],"articleSection":["Laravel","PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/","url":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/","name":"Laravel Package Development | Laravel Website Development","isPartOf":{"@id":"https:\/\/www.200oksolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#primaryimage"},"image":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#primaryimage"},"thumbnailUrl":"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","datePublished":"2024-04-11T09:26:01+00:00","dateModified":"2025-12-04T07:44:09+00:00","description":"Custom Laravel package or to start from scratch? Follow these six easy steps, read this article, and learn how to create a Laravel package.","breadcrumb":{"@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#primaryimage","url":"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","contentUrl":"https:\/\/www.200oksolutions.com\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","width":728,"height":311,"caption":"laravel-custom-package-development"},{"@type":"BreadcrumbList","@id":"https:\/\/www.200oksolutions.com\/blog\/custom-laravel-package-development\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.200oksolutions.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom Laravel Package Development"}]},{"@type":"WebSite","@id":"https:\/\/www.200oksolutions.com\/blog\/#website","url":"https:\/\/www.200oksolutions.com\/blog\/","name":"Web Development, Software, and App Blog | 200OK Solutions","description":"","publisher":{"@id":"https:\/\/www.200oksolutions.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.200oksolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.200oksolutions.com\/blog\/#organization","name":"Web Development Blog | Software Blog | App Blog","url":"https:\/\/www.200oksolutions.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.200oksolutions.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/200oksolutions.com\/blog\/wp-content\/uploads\/2025\/09\/200ok_logo-CGzMrWDu.png","contentUrl":"https:\/\/200oksolutions.com\/blog\/wp-content\/uploads\/2025\/09\/200ok_logo-CGzMrWDu.png","width":500,"height":191,"caption":"Web Development Blog | Software Blog | App Blog"},"image":{"@id":"https:\/\/www.200oksolutions.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.instagram.com\/200ok_solutions\/"]},{"@type":"Person","@id":"https:\/\/www.200oksolutions.com\/blog\/#\/schema\/person\/e07f6b8e3c9a90ce7b3b09427d26155e","name":"Piyush Solanki","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.200oksolutions.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/962a2b0b4db856e6851ec7d838597a0395adcaae9c0091d223de9942a4254461?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/962a2b0b4db856e6851ec7d838597a0395adcaae9c0091d223de9942a4254461?s=96&d=mm&r=g","caption":"Piyush Solanki"},"description":"Piyush is a seasoned PHP Tech Lead with 10+ years of experience architecting and delivering scalable web and mobile backend solutions for global brands and fast-growing SMEs. He specializes in PHP, MySQL, CodeIgniter, WordPress, and custom API development, helping businesses modernize legacy systems and launch secure, high-performance digital products. He collaborates closely with mobile teams building Android &amp; iOS apps , developing RESTful APIs, cloud integrations, and secure payment systems using platforms like Stripe, AWS S3, and OTP\/SMS gateways. His work extends across CMS customization, microservices-ready backend architectures, and smooth product deployments across Linux and cloud-based environments. Piyush also has a strong understanding of modern front-end technologies such as React and TypeScript, enabling him to contribute to full-stack development workflows and advanced admin panels. With a successful delivery track record in the UK market and experience building digital products for sectors like finance, hospitality, retail, consulting, and food services, Piyush is passionate about helping SMEs scale technology teams, improve operational efficiency, and accelerate innovation through backend excellence and digital tools.","url":"https:\/\/www.200oksolutions.com\/blog\/author\/piyush\/"}]}},"_links":{"self":[{"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":7,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":535,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions\/535"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/media\/517"}],"wp:attachment":[{"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.200oksolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}