Create package for a Laravel method

  laravel, package

I have a laravel method inside on one of my controllers. I have used it on two of my projects so I thought of making a package for that specific method so that I can just require it on my future projects.

I was able to put it on github and packagist, but I cannot make it work on a laravel project.

Here are what I have so far:

Composer.json :

"autoload": {
          "psr-4": {
          "App": "app/",
          "vendorpackage": "src/"
      }
    },
    "extra": {
        "laravel": {
            "providers": [
                "vendorpackagePackageServiceProvider"
            ],
            "aliases": {}
        }
    },
    "require": {}

ServiceProvider :

namespace vendorpackage;

use IlluminateSupportServiceProvider;

class PackageServiceProvider extends ServiceProvider
{        
    public function boot()
    {
      //
    }
        
    public function register()
    {
      //
    }
}

Now, here is where I am stock. What should I do next to make the function below working as a package:

public function sumThis($first_number, $second_number)
{
  $sum = $first_number + $second_number;

  return $sum;
}

Source: Laravel

Leave a Reply