Laravel: Collaborative Development

Start Working With Laravel In A Collaborative Environment

Posted on February 23, 2017 in Laravel Tutorials

Laravel is the most popular PHP framework among the web developer community right now. If you need to implement a web application using PHP and following the MVC architectural pattern (MVC: Model-View-Controller) with expressive, elegant syntax, Laravel is the best-recommended option for you. Laravel is free, open-source, accessible, yet powerful, providing powerful tools needed for large, robust applications.

If you are a complete beginner, you can refer my previous tutorial, Laravel 5: Getting Started to know how to start a fresh Laravel project. As the topic states, this tutorial is for those who wish to start collaborative development with Laravel (i.e. for those who want to contribute to the development work of an already-started Laravel project)

Ground Rules

You must have installed the following development tools in your local environment.

  1. XAMPP (Cross-platform Apache MySQL PHP Perl ) / WAMP (Windows Apache MySQL PHP) / LAMP (Linux Apache MySQL PHP) : To run and test any PHP project on your local machine, you need a web server software which can convert your computer into a server and provide the ability to host your files locally. XAMPP can be installed and easily configured with the instructions here
  2. phpMyAdmin : If you are using XAMPP, you will get phpMyAdmin with XAMPP installation package. Unfortunately, LAMP users will have to install phpMyAdmin manually to their machines. 
  3. Composer : Composer is a popular dependency management tool for Laravel. In simple terms, it has the capability to read a file (composer.json, composer.lock) in your Laravel directory and download the essential dependencies for your project. 
  4. Git : Git is a popular version control system used by the professionals all over the world. (Git was originally created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development.) Although Git is not very necessary for the basic implementation of Laravel, you will face lots of problems during the development life cycle if you ignore this requirement. Also, you must note that Git is a highly-recommended tool for any kind of development work. During the Git installation, make sure you enable both Command Prompt access and Bash access of Git commands. 

Unfortunately, you cannot learn Laravel overnight. But a good commitment and passion will help you to stay focused and do great things with Laravel over the time.

Collaborative Development

1) Access to remote repo.

Your team must have a web-based Git repository hosting service to keep your code safe online and take it everywhere you go. Using an online repository lets the team members have access to your code online, download and develop it on another machine, add other team mates and encourage collaborative development, and have many benefits at the later stages of the development cycle. There exist two very famous hosting services which support Git version controlling: Github and BitBucket. Github is my favorite. You cannot simply find a developer without a Github account, it is that famous.

First of all, make sure you have access to the remote repository of your project folder. Ask your lead developer to add all the team members to the repository created by him. When you get access, go to the repository and copy the Git URL of your project.

2) Clone the remote repository to your local machine.

It is hard to make changes to your project online. So let’s take a copy to your local machine for development purposes.

As you all know, using XAMPP (or a similar local server), you can only access to the files which are located inside the htdocs directory (~/xampp/htdocs/). Therefore first of all, go to this directory using your terminal (Command Prompt, Git Bash or Linux Terminal). Git commands have no difference on any terminal. But other general commands have variations for Windows Command Prompt and Linux Terminal. Git Bash uses the Linux commands, but it is a light weight terminal in comparison to Linux Terminal. 

After going into the htdocs directory using your terminal, you can clone the repo using this command,

git clone

The above Github link in the command is the URL you copied in the previous step. To verify this action, go to the htdocs and check the newly-created directory for your project. Your folder must look something similar to the screenshot of my “management_system” project folder.

3) Create all dependencies using Composer.

If you carefully look at the Laravel online repository and the documentation, you can notice how often the technologies are changing over the time. Therefore keeping all vendor files (libraries, bug fixes, latest updates) with Laravel installation folder is not a good idea because the user might miss the latest updates. (Also, the installation folder might be unnecessarily large) To overcome this issue, only a list of dependencies is kept inside the Laravel installation folder. When time comes for the usage, we can download the recommended vendor files inside the Laravel folder using the dependency management tool called Composer. You can get the vendor files using this command;

composer install

This command will install all the dependencies as specified in the composer.lock file. To verify the action, check the newly-created vendor directory in your Laravel directory.

Installation part is now over. Before getting started with our development work, we have to make few configurations in the development environment.

4) Configure environment settings and generate Application Key.

In your Laravel folder, you can see the .env.example file. Actually this configuration file is there only for the reference purposes of the developer. To run Laravel, you need a .env file inside the Laravel folder, which is something you need to add manually. The content in the .env file is very similar to the content in the .env.example file. So let’s first copy the .env.example file and then edit its content to get the .env file for our use. To copy the file, run this command,

For Linux/Git Bash: cp .env.example .env 
For Windows        : copy .env.example .env

(If you open the .env file, you can notice that the default string assigned to APP_KEY is “SomeRandomString” which is only 16-characters long. You will wonder why 32 characters are needed. That is because there is a rule defined in Laravel’s config/app.php file as so: ‘cipher’ => ‘AES-256-CBC’. An advanced user can manipulate these values inside Laravel’s config directory as per the requirement.)

Next, we have to assign a valid string as our application key in the .env environment file. Typically this string should be 32-characters long.
To generate a valid string for APP_KEY, run this command,

php artisan key:generate

The command should automatically update the app.php file (and also the .env file) with a new proper-size key, and output the generated key on your terminal. You can verify that this key is now in Laravel’s .env file. If it is not there, you will have to manually replace the 16-char-long string with a new 32-char-long string you like and save the changes in .env file.

The basic configurations are now over and you can run the Laravel project on your browser and see whether it is working fine. Open your browser, go to http://localhost/management_system/public/ and you will see the project, if the installation is successful. If your team has not yet started the development work, you will see the default welcome screen of Laravel. In my case, we have already done our login interface and it comes to my screen when I try to access the public folder.

5) Create MySQL database using phpMyAdmin.
As we all know, we use tables to store data in a database. Let’s setup a database connection for our Laravel project. On your browser, go to http://localhost/phpmyadmin and create a new database with a nice name. In my case, I name my database as “management_system”.

6) Configure the database connections.

Now open the .env file again and change the values of each variable as follows.


In case you have changed the default ports in your XAMPP server, make sure you use the new port number for DB_PORT. (e.g:- DB_PORT=330633)

The MySQL module coming with XAMPP package does not have a password by default. Therefore I have removed the DB_PASSWORD line completely in the above example. Also note that root is the default username. 

7) Migrate the database connections.

If your project has tables which have already been implemented, you need to run a migration code to create all those tables in your local database as follows,
php artisan migrate  
To verify, go to http://localhost/phpmyadmin and check your database. There must be newly-created tables inside your database.

8) Commit changes to Git.

You can now start the development work with Laravel. First of all, add all changes to Git with the below commands,
git add . 
git commit –m “Initial Commit” 
git push origin master
Congratulations, you are now all set to contribute to a great Laravel project! Happy coding folks!

Recommended Study Resources for Beginners

If you are a beginner and have no idea on where to start, you may just have a look on this video series. You have a lot to learn in Laravel, but this video series would make your life easy.

Laravel PHP - Create a Social Network (Full App) by Mindspace - View Playlist (22 Videos)

comments powered by Disqus