Thursday, December 29, 2016

Creating a sample laravel 5.2 Project with PHPUnit

Creating a sample laravel 5.2 Project with PHPUnit

Laravel Installation

First we need to install the laravel. 

Commonly laravel is installing using Composer. So if you are not installed the composer first we need to install it in your system.

We can install the composer from the url : https://getcomposer.org/download/

After installing the composer take the Terminal and go to the directory where you need to create the project.

Now from the terminal run the following command  and it will create the laravel project in the 'Student' directory.

composer create-project laravel/laravel Student

Wait for some time and it will install the laravel for you.


Now the installation is finished and take the url http://localhost:8080/ 

It will show the 'Student' directory there and take it and then take 'Public' folder. Now you can see the 'Laravel 5' welcome screen on the browser.

Now we are going to create a database for storing the students info.

Take the phpmyadmin (Hopefully it is in http://127.0.0.1:8080/pma/) and create a database named Students.

Now we need to fill the database details in the .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Students
DB_USERNAME=root
DB_PASSWORD=root

Now we need to create a migration for creating the table in the database.

For it run the following command from the terminal from the students directory:

php artisan make:migration create_students_table

This will create a migration file in the database/migrations folder.

Open it and update the up() function with the following content.

Schema::create('students', function(Blueprint $table)
{
$table->increments('id');
$table->string('name')->default('');
$table->string('class')->default('');
$table->timestamps();
});

Fill the down() function with the following content

Schema::drop('students');

Then from the terminal run the command : 

php artisan migrate

This will create the students table in the Students database. Please check it.








Monday, December 26, 2016

Solution for not affecting the changes in .env file in laravel

Laravel : After make changes to env file it is better to run the following command to affect the new changes in your application.

If you change the .env file content and it is not affecting then run the following command from the command prompt

php artisan config:cache

It will show the following result :

Configuration cache cleared!
Configuration cached successfully!