laravel-custom-package-development

Custom Laravel Package Development

Share this post on:

Requirements :

  • Laravel v 5.5 or above is required.
  • Composer is installed on your system. You may get Composer here if you don’t already have it.

Step 1: Install the Laravel App

  • The first step is to construct a Laravel website. We’ll use Composer to set it up. Check out the official Laravel documentation for more installation options.

Step 2: Project Structure

  • PHP Composer is used to update dependencies and publish packages. A Composer is a tool for dependency management in PHP.
  • Before creating the composer.json file, create the below folders inside your Laravel project

Step 3: Create Composer File

  • Use the below command to generate composer.json
  • The composer.json file should now look like this.
  • Let us begin with autoloading the newly created package via the autoload block and add that code in composer.json.

Step 4: Adding Routes.php File

  • This will be accomplished by creating new routes.php in the package src dictionary, you can simply copy and paste the below-shown also.
  • After this include the routes.php file inside the boot() method of the service provider’s boot method.

Step 5: Add Package Service Provider

  • At the root of our app, let’s create our ServiceProvider with an artisan command via the command line.
  • After its process is completed, you’ll find a new file located at:
  • app/Providers/CustomServiceProvider.php
  • The next step will include moving this file into the package folder, the location will be:
  • packages/test/custom_package/src/CustomServiceProvider.php
  • Don’t miss out on changing your namespace to be:
  • Next, the last step of this pointer will be the addition of a new service provider in the large bracket – [] array mentioned in config/app.php:

Step 6: Create a Package controller

  • After its process is completed, you’ll find a new file located at:
  • app/Http/Controllers/CustomController.php
  • The next step will include moving this file into the package folder, The location will be:
  • packages/test/custom_package/src/CustomController.php
  • Now that we have created our controller, we will need to register it. Inside our Service Provider class in the register() method.
  • Finally, let’s add a few more routes to our routes.php file
  • Then, if we navigate to http://127.0.0.1:8000/add/4/4 and
    http:/127.0.0.1:8000//subtract/8/4 We end up with the following results!

Author: Piyush Solanki

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 & 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.

View all posts by Piyush Solanki >