I already know how to install by going through composer.json to add laravel/cashier, then composer update, and then add some line in app provider. But where does this folder go? What other things does it add in my app to make it fully functional? What is the work flow of composer update in Laravel 4?
Composer is a dependency management tool for PHP. It is not a typical package manager as it does not install libraries globally, but on a per project basis. It uses the file "composer.json" to install, update and remove libraries specified, including the version requested.
Composer creates an "autoload.php" file that, if included in your project, autoloads all libraries and classes and makes them available for use.
Typically, in a regular PHP project, you'd include the following line to bootstrap your project:
require 'vendor/autoload.php';
Now, when you execute composer install (for first time) or composer update (every time after), Composer adds/removes packages according to configuration made in "composer.json" file. All packages go in the directory "vendor" found in root of your project directory.
Laravel, by default, is a Composer project. You know when you execute composer create-project laravel/laravel my-app --prefer-dist to install Laravel, you are telling Composer to build a "composer.json" file with Laravel project and its dependencies, and run composer install. That's all!
Last but not least, Laravel, since it is a Composer project, includes "autoload.php" file and autoloads all packages within that project by default. You will notice "vendor" directory in the root directory. In Laravel 5 project, if you navigate to "bootstrap/autoload.php" file, you will see Laravel includes "autoload.php" file: require __DIR__.'/../vendor/autoload.php';
To answer your question about manually installing Laravel Cashier, Laravel Cashier is a package made specifically for Laravel, and as such, is not meant to be used on regular PHP project, unless you use specific classes and do some tweaking. To manually install Laravel Cashier, if you go to the following link, you will find link to "laravel/cashier" GitHub repository, from where you can manually download Zip file or clone the repository using git:
https://packagist.org/packages/laravel/cashier
I hope this adequately answers your questions - I kept it as simple as I could. Let me know if you have any other questions.
Related
Is there any way to install laravel from only composer.json file by using
composer install
command. If i just copy composer.json from existing project it creates only vendor directory, but not app, database, etc.
I just want to load all laravel core files, project file structure and my custom package by using install command of composer.
Can someone help me with this?
You can install laravel with the command composer create-project --prefer-dist laravel/laravel <project_name> if you only want to use composer, this command is mandatory since it creates the directories you want.
See the documentation
I don't think you can.
Create a new laravel project or clone an old project from git. Then replace/update the composer.json, then run composer update, if its a new project or composer install, if you cloned a repo
I didn't find solution for this, maybe it's impossible.
So, i just create my package and manually copy my custom composer.json to project.
I am thinking to create a project skeleton in the following format via a composer package that I am going to create.
/app
/config
/web
/vendors
Just wondering about this command
composer create-project vendor/name path
--repository-url=http://repo.yourcomposerrepo.com
What do I need to put in the composer.json in order to create the file structure I want? Is it done through the shell script or it just copied the files from the repositories?
For symfony it will create the files and folders automatically through composer create-project. Just wondering how do I achieve the similar thing for this case. When I looked at their repo it only contains one composer.json at https://github.com/symfony/skeleton
composer create-project symfony/skeleton blog
Thank you.
composer create-project will create a new directory with all the files that are part of that package and then it will run the installation for all the dependencies that are listed in that package's composer.json file.
If you want to have a better example to understand that, you can use the old way that we used to bootstrap Symfony applications (when not using the Symfony installer). Then applications were based on the Symfony Standard Edition which you can find on GitHub. Just run composer create-project symfony/framework-standard-edition and compare the result with the repository.
Using symfony/skeleton as the base package is a bit special. This package depends on Symfony Flex which is a Composer plugin that automatically applies so called recipes (see https://flex.symfony.com/) which will lead to newly created files when a package is installed (and clean them up on removal). But, this behaviour is special for Flex and thus nowadays Symfony 4 based application and not a good example for what composer create-project does by default.
I am starting a new PHP project, and I wanted to pull some php components such as "nesbot/carbon" using composer. But when I create a composer.json file and try to run composer install command, it downloads other files from my previous projects that I don's want.
Even when I try to run "composer install" with out having a composer.json file in an empty folder, it downloads some previous dependencies from caches. I didn't get that from where it's reading composer.json. Am stuck in the middle of project.
How can I create a fresh project with composer?
To create a fresh project with composer, run
$ composer init
in the root directory of that project.
For reference, see https://getcomposer.org/doc/03-cli.md#init.
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.
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.