Laravel 5 package development clarity

2019-09-02 18:45发布

问题:

Ive been reading a few articles on the net about package development but cant quite wrap my head around the basic setup. Ive written jQuery plugins with releases and published to Bower in the passed so maybe im just not understanding the difference with Laravel.

With jQuery plugin dev I would just exclude my dev required dependancies through bower.json to prevent a person pulling in my dependancies. It seems that with Laravel u create an un-tracked Laravel framework folder and put your package into the vendor folder and track only that with Git? So basically the Laravel project sitting outside of my vendor package is just some files on my PC? Surely I would want to track which version of Laravel the package was developed on?

OR should I create a "base" Laravel repository and create another repository inside the vendor folder so make sure I know which Laravel the package was built on?

Documentation and tutorials are very vague...

回答1:

Your question looks a little bit confuse. I develop packages for Laravel and the following is a regular way:

  1. Laravel manage its dependencias via composer, take a look into composer.json to get a clue how similiar is with bower.
  2. In order to get yout package compatible with laravel's core you need to implement some interfaces in your package. This package also can manage dependencies via composer.
  3. A package can be created as a repository in different version controls, like Github, BitBucket, Packagist, Cartalyst, private packages repositories, etc. By default laravel pull packages from Packagist, but into composer.json file you can specify another reposository as needed.
  4. When you trigger composer update (this is an equivalent as bower update), this dependencies manager will pull all the packages and download them automatically in vendor/ directory.

How to code your package while testing with laravel? some people do the following, including me:

  1. Install a laravel instance just for package development purpose.
  2. Create a new project (your package project) inside of vendor/project-name following lavavel's package requirements.
  3. Keep working your package from this project location. By this way the changes are reflecting instantly in laravel installation.
  4. Don't forget to commit and push