Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Created package in Laravel workbench, but how to transfer to vendor folder?

Let's say my package in Laravel is test/test.

I created the package in the workbench and it's been working great following Jason Lewis' tutorial. Now I want to move the package out of the workbench to the vendor directory. This is where all tutorials fall short, even the laravel docs. I didn't want to use git to move the files, so I simply copied the test/test package from the workbench to the vendor directory (and then deleted it from the workbench). I didn't copy the test/test/vendor folder from the workbench (or any other files I noticed in the .gitignore file). I then ran composer install from my new vendor/test/test directory. I then did a composer dump-autoload from the laravel root directory.

Now when I run my application I get an error that I did not get when the package was in the workbench:

Class 'Test\Test\TestServiceProvider' not found
(this is coming from \bootstrap\compiled.php on line 4121)

I also did a php artisan dump-autoload from the laravel root and I get this same error.

Any ideas? Or can someone lead me to a tutorial that takes the package development all the way to it's final resting point in the vendor directory?

like image 723
prograhammer Avatar asked Jul 18 '13 15:07

prograhammer


People also ask

Where is vendor folder in Laravel?

Role of vendor folder in Laravel The vendor is a subfolder in the Laravel root directory. It includes the Composer dependencies in the file autoload. php. Composer is a PHP based tool for dependency management.

How many packages are in Laravel?

As of now, there are over 500 Laravel packages on. They offer all sorts of functionality from booking and travel to eCommerce and instruction.

What is a Laravel pack?

Packages might be anything from a great way to work with dates like Carbon or a package that allows you to associate files with Eloquent models like Spatie's Laravel Media Library. There are different types of packages. Some packages are stand-alone, meaning they work with any PHP framework. Carbon and PHPUnit are examples of stand-alone packages.

What is the vendor folder in Laravel?

The vendor is a subfolder in the Laravel root directory. It includes the Composer dependencies in the file autoload.php. Composer is a PHP based tool for dependency management. As a Laravel project works with many libraries, it requires the Composer for dependency management. An outdated Composer cannot create an autoload.php and vendor folder.

Why can’t i load my Laravel project with artisan?

As a Laravel project works with many libraries, it requires the Composer for dependency management. An outdated Composer cannot create an autoload.php and vendor folder. Hence the whole Laravel project won’t work. Therefore, when the user tries to load the Laravel project via the command-line tool Artisan, it ends up with a PHP warning.

How do I create a custom package in Laravel?

To initialize a new Laravel custom package development, cd into the packages/fhsinchy/inspire directory and execute the composer init command. This will start the package initialization process. Make sure to write the package name, description, and author information properly.


1 Answers

Got it working.

I added:

"psr-0": {
    "Test\\Test": "vendor/test/test/src/"
}

to the autoload section in composer.json in the laravel root directory so it looks like this:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "psr-0": {
        "Test\\Test": "vendor/test/test/src/"
    }       
},

If I decide to put the package on Packagist later then I might remove this from the autoload and just keep the package referenced in the "require" part of my composer.json. We'll see what happens when I get that far!

like image 127
prograhammer Avatar answered Sep 21 '22 10:09

prograhammer