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.
Related
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 install a new Laravel project and I have been applied Many changes on it for my own purposes. for Example my custom admin panel design and related css and javascript files.
In addition to, I added some packages that are required on whole project.
Now , if I want to Start a new Project , I must to install a fresh laravel Project and add those files and packages manually again that It takes a lot of time.
Is there a way that I could store this base laravel project on it (for example Github) and install it via composer?
Yes, you can use Github to create a private/public repository then when you start e new project you clone that repository and then use composer install command to get the dependencies.
Yes, it's possible.
Here are all the steps :
git clone xxx.git
composer install (make sure you have included .env.example in your git for the app key)
npm install
bower install
php artisan migrate (if, I hope, you use migrations)
gulp
And you are ready to work on your project.
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 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.
Every time I create a new PHP project I basically use the same MVC folder structure that I adopted and like, I use the same base classes, interfaces, and the same PDO DAL implementation.
When I'm creating a new project I copy&paste all the needed files to the new project in addition to few changes, like changes to namespaces (to match the new project name) etc.
I thought, why not creating a simple script to copy those files and folders, and make the additional changes.
So now, when I create a new project I just run the script and the code is generated automatically, which is much nicer.
And then I thought, I want it to be even simpler. I don't want to save the code in my computer, I want to save it on Github, and since I use and love composer, I thought I will make the Github project a composer package.
But when trying to implement it I realized that I can't make the new composer package auto generate the code that I want, or at least I don't know how to make it do that.
I tried googling it with no success.
Does anyone knows how to achieve this?
I don't see any need to generate code here. Simply add your skeleton files to your Git repository and use Composer's create-project feature. See the third point:
You can use Composer to create new projects from an existing package. This is the equivalent of doing a git clone/svn checkout followed by a composer install of the vendors.
There are several applications for this:
You can deploy application packages.
You can check out any package and start developing on patches for example.
Projects with multiple developers can use this feature to bootstrap the initial application for development.
An example of a major PHP project that supports this approach is Laravel. From its installation instructions:
Via Composer
The Laravel framework utilizes Composer for installation and dependency management. If you haven't already, start by installing Composer.
Now you can install Laravel by issuing the following command from your terminal:
composer create-project laravel/laravel your-project-name --prefer-dist
This command will download and install a fresh copy of Laravel in a new your-project-name folder within your current directory.
If you prefer, you can alternatively download a copy of the Laravel repository from Github manually. Next run the composer install command in the root of your manually created project directory. This command will download and install the framework's dependencies.
Edit:
To have a script run after composer create-project completes you should be able to use a Composer script:
A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command. Scripts are useful for executing a package's custom code or package-specific commands during the Composer execution process.
You are probably looking for the post-create-project-cmd event:
occurs after the create-project command is executed
Depending on whether your script is a static PHP method or a shell executable, you should define it as follows (modified from Composer documentation):
{
"scripts": {
"post-create-project-cmd": "MyVendor\\MyClass::postUpdate"
}
}
or
{
"scripts": {
"post-create-project-cmd": "my-shell-script arg1 arg2"
}
}