{"id":514,"date":"2024-04-11T09:26:01","date_gmt":"2024-04-11T09:26:01","guid":{"rendered":"https:\/\/200oksolutionssandbox.co.uk\/blog\/?p=514"},"modified":"2024-04-18T11:13:28","modified_gmt":"2024-04-18T11:13:28","slug":"custom-laravel-package-development","status":"publish","type":"post","link":"https:\/\/200oksolutionssandbox.co.uk\/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:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/output-1.png\" alt=\"\" class=\"wp-image-519\" style=\"width:354px;height:auto\" srcset=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/output-1.png 319w, https:\/\/200oksolutionssandbox.co.uk\/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:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/output-2.png\" alt=\"\" class=\"wp-image-520\" style=\"width:350px;height:auto\" srcset=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/output-2.png 338w, https:\/\/200oksolutionssandbox.co.uk\/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&hellip;<\/p>\n","protected":false},"author":1,"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 v22.5 - 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:\/\/200oksolutionssandbox.co.uk\/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:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/profile.php?id=61552217825863\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-11T09:26:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-18T11:13:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/200oksolutionssandbox.co.uk\/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=\"BlogAdmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"BlogAdmin\" \/>\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:\/\/200oksolutionssandbox.co.uk\/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:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/","article_publisher":"https:\/\/www.facebook.com\/profile.php?id=61552217825863","article_published_time":"2024-04-11T09:26:01+00:00","article_modified_time":"2024-04-18T11:13:28+00:00","og_image":[{"width":728,"height":311,"url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","type":"image\/png"}],"author":"BlogAdmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"BlogAdmin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#article","isPartOf":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/"},"author":{"name":"BlogAdmin","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/ea0b72006227b3403f5ad825b82ced43"},"headline":"Custom Laravel Package Development","datePublished":"2024-04-11T09:26:01+00:00","dateModified":"2024-04-18T11:13:28+00:00","mainEntityOfPage":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/"},"wordCount":384,"commentCount":0,"publisher":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#primaryimage"},"thumbnailUrl":"https:\/\/200oksolutionssandbox.co.uk\/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:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/","name":"Laravel Package Development | Laravel Website Development","isPartOf":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#primaryimage"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#primaryimage"},"thumbnailUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","datePublished":"2024-04-11T09:26:01+00:00","dateModified":"2024-04-18T11:13:28+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:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#primaryimage","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","contentUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/04\/laravel-custom-package-development.png","width":728,"height":311,"caption":"laravel-custom-package-development"},{"@type":"BreadcrumbList","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/custom-laravel-package-development\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/200oksolutionssandbox.co.uk\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom Laravel Package Development"}]},{"@type":"WebSite","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#website","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/","name":"","description":"","publisher":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/200oksolutionssandbox.co.uk\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization","name":"Web Development Blog | Software Blog | App Blog","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2026\/01\/200ok_logo.png","contentUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2026\/01\/200ok_logo.png","width":500,"height":191,"caption":"Web Development Blog | Software Blog | App Blog"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/profile.php?id=61552217825863"]},{"@type":"Person","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/ea0b72006227b3403f5ad825b82ced43","name":"BlogAdmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/53ecc99d859b4d3444ee1e076f3b5d9da9962836d1c20b3b44d73574f435740d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/53ecc99d859b4d3444ee1e076f3b5d9da9962836d1c20b3b44d73574f435740d?s=96&d=mm&r=g","caption":"BlogAdmin"},"sameAs":["http:\/\/blog.200oksolutions.com"],"url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/author\/blogadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":7,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":535,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions\/535"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/media\/517"}],"wp:attachment":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}