laravel publish dependancy packages assets - php

I am just starting to learn about laravel packages, and started my first package.
My package requires some other packages installed in the vendor directory of my package via composer. When I come to do assets:publish my package, I need it to also assets:publish the vendor packages as well.
How do I go about automating this, or is it just a matter of guiding the user through publishing each package separately?

You can in Laravel call artisan inside of your application or package:
Artisan::call('assets:publish', array('--package' => 'Vendor/PackageName'));

Related

How can I put my own laravel package on github?

I developed a Laravel package which is currently located in the vendors folder of my Laravel 5.3 installation.
I am trying to put this package on GitHub so other people can use it. Also I want to be able to sync this package only (not the entire Laravel project) to the GitHub repository so I can commit any changes later.
What steps should I take to put this new package for the first time on GitHub and how can I keep the local project synced up with the version on GitHub?
Please have a look to this: (You most likely want to create a composer package)
https://knpuniversity.com/screencast/question-answer-day/create-composer-package
To put the package on GitHub follow these steps:
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
To keep the project "synced up" commit and push changes that you make to the Laravel package, and they will show up on GitHub.
git add .
git commit -m "commit message here"
git push
Note: git add . adds all changes.
Use git add [filename] to add specific files.
Laravel works with composer package manager so you have to make a composer package
from the Composer Official Documentations :
A repository is a package source. It's a list of packages/versions.
Composer will look in all your repositories to find the packages your
project requires.
By default only the Packagist repository is registered in Composer.
You can add more repositories to your project by declaring them in
composer.json.
so all you need is a composer.json which contains your Project files here is a good tutorial for creating your very own packages
create-composer-package

Manually laravel 5 package install in project

I have install a new laravel 5 project. In my other project i have several packages. I want to install my expected packages from copying package from vendor folder and paste into my new project. I want to do that because composer is really slow to install new package from online.
You just can't install manually because it will be a lot of task then. e.g when Laravel installs through composer it has some scripts which runs at different steps of install it copies .env file it generates key etc. You can see https://github.com/laravel/laravel/blob/master/composer.json#L31 & https://getcomposer.org/doc/articles/scripts.md#event-types. Now you can copy paste of your full previous code & remove controllers, models, packages from composer.json. But if you manually install it won't be a wise decision.
For composer You can use https://github.com/hirak/prestissimo
It gives you the ability to install packages and dependencies in parallel mode. This gives a huge boost during installing projects/packages.

Getting started with laravel

I just started my laravel course with laracast. I dont quite understand yet all the enviornment-related things.
I know that Composer is a kind of a program that downloads pre-written scripts to use in your project. But where does it work? On my local machine or on my vagrant homestead box VM? On which of these is it supposed to be installed?
I installed myself vagrant homestead box already but does it contain composer? When I go ssh into my guest machine and go to vagrant#homestead:/vagrant$ path I can see composer.json and composer.lock files, but does it mean that I have composer installed?
Composer is a PHP package manager, like npm for javascript or pip for python. There are many examples of package managers. It's useful, because adding dependencies to your php projects can be a pain, but composer makes it really easy. You just add the dependency to composer.json and you can use it right off the bat.
Composer isn't laravel specific, you can use it in any php project, laravel uses it to manage it's dependencies, laravels dependencies use it to manage their dependencies and so forth.
If nothing else, the composer autoloader is great, so you can use it even if you don't plan on using external packages.
Homestead should come with composer installed. A composer.lock file is generated when you run a composer install or composer update. If you plan on creating or using other php projects on your machine, it's probably a good idea to have composer installed on your machine as well.

How to develop and test Laravel package in isolation?

I have a Laravel 5.1 application that I've built a couple of custom packages inside of (I follow this tutorial). These packages have no dependencies that didn't already exist in the root Laravel app.
My first question is, if I needed to add a dependency to the package that wasn't already in the root app, how would it get pulled into the root app? Running composer update or composer install from the root application does not pull them in. I understand that once I publish to GitHub and later pull the package into my app with Composer, that it's dependencies will pull in...but how do I do it while developing?
My next question is, how do I go about creating automated tests for this package? None of the tutorials I've found address this. Should the package be in it's own instance of Laravel with the tests inside of the tests directory?
To pull in dependencies for your own package, you will need to navigate to your package root (not your application root) and run the composer update and composer install commands from there. That should create a vendor directory local to your package which will contain all dependencies declared in your package's composer.json.
The same goes for testing - you can create a tests directory local to your package inside the larger Laravel app and run your tests from the package root. Just make sure to include your testing dependencies inside your package's composer.json.

Should I download Laravel for every project?

I created a project with Laravel and downloaded from git via this command:
git clone -b develop git://github.com/laravel/laravel.git
The file size was about 21MB,
I want to know should I download Laravel for every project with this command?
What you have done is cloned the framework itself, which you should only do if you're going to fork and develop the Laravel core.
What you should do instead is use Composer to install your Laravel projects. You'll also be using Composer for other dependency-related actions in said projects (including autoload). This is the proper way of installing a fresh Laravel framework for developing a website:
composer create-project laravel/laravel --prefer-dist
http://laravel.com/docs/installation
Then, any future Laravel projects you create will be loaded from your Composer cache without needing to re-download.
The Composer package also sets up all your vendor-related .gitignore information and includes several other really useful management features. This is important, because you only want to keep your application-specific code under git version control, not the framework itself or any other dependencies. (Otherwise, your diffs and commits will get polluted with the dependencies' development changes.)
Once you've created a repository for your project, and installed Laravel with Composer, and created your first few commits (with some migrations, models, and controllers, for instance), cloning your project usually works something like this:
cd /clone-here
git clone /myproject # Location of current project
# /clone-here now has only the application-specific files from /myproject. It is
# still missing the framework itself and other dependencies.
composer install # Composer now looks at the dependencies in
# /clone-here/composer.json and installs them into /clone-here/vendor
# including the Laravel framework.
# Now the framework and other dependencies are good to go.
php artisan migrate # Laravel makes all your DB schemas from your migrations
php artisan db:seed # Seed your lovely new DB tables
It's really elegant and fun once you get used to it.
Edit:
See Sheikh's answer to save some time in the Composer install process!
Already Leng gave a nice answer.
Installing Laravel since version-4.1* via Laravel Installer is faster than composer
First, download the Laravel installer PHAR archive. For convenience,
rename the file to laravel and move it to /usr/local/bin. Once
installed, the simple laravel new command will create a fresh Laravel
installation in the directory you specify. For instance, laravel new
blog would create a directory named blog containing a fresh Laravel
installation with all dependencies installed. This method of
installation is much faster than installing via Composer.

Categories