15
1 Author : Vikas Chauhan Presented By: Vikas Chauhan Software Engineer, BrainCoerce Technologies, Bangalore Date 08/18/2013

Laravel Beginners Tutorial 2

Embed Size (px)

Citation preview

Page 1: Laravel Beginners Tutorial 2

1 Author : Vikas Chauhan

Presented By:

Vikas Chauhan

Software Engineer,

BrainCoerce

Technologies, Bangalore

Date – 08/18/2013

Page 2: Laravel Beginners Tutorial 2

2 Author : Vikas Chauhan

Exercise 1 :- Migration & Artisan

Exercise 2 :- Database Setup

Exercise 3 :- Create Table Using Migration & Artisan

Exercise 4 :- Add Data Into Table Using Migration & Artisan

Page 3: Laravel Beginners Tutorial 2

3 Author : Vikas Chauhan

Exercise 1

Migration & Artisan

Page 4: Laravel Beginners Tutorial 2

4 Author : Vikas Chauhan

Artisan :- Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands.

To view all available Artisan commends type “<project_dir>/ php artisan list “

on your command line.

Migration :- Migrations are a type of version control for your database.

It allows me to create my tables easily, without writing a single line of database language for example :- mysql etc.

Before install migration in your project you need to be configure your database file.

Page 5: Laravel Beginners Tutorial 2

5 Author : Vikas Chauhan

Exercise 2

Database Setup

Page 6: Laravel Beginners Tutorial 2

6 Author : Vikas Chauhan

<project_dir>/app/ config / database.php :-

Page 7: Laravel Beginners Tutorial 2

7 Author : Vikas Chauhan

Exercise 3

Create Table Using Migration & Artisan

Page 8: Laravel Beginners Tutorial 2

8 Author : Vikas Chauhan

On command line :- “php artisan migrate: install” (migration table should be add in you database)

On command line :- “php artisan migrate: make create_authors_table” (create a authors table into database)

<project_dir>/ app/ database/ migration /2013_08_07_101708_create_authors_table.php :-

That php file contain two function up() & down(). up() function is used for create table and down() function is used for destroy table and its data. For example :-

Page 9: Laravel Beginners Tutorial 2

9 Author : Vikas Chauhan

class CreateAuthorsTable extends Migration

{

public function up()

{

Schema::create('authors', function($table){

$table->increments('id');

$table->string('name');

$table-> text('bio');

$table->timestamps();

});

}

public function down()

{

Schema::drop('authors');

}

}

Page 10: Laravel Beginners Tutorial 2

10 Author : Vikas Chauhan

On command line :- “php artisan migrate” (for perform action on up function)

On command line :- “php artisan migrate: rollback” (for perform action on down function)

If you will see fatal error while you rollback the migration :-

on command line :- “var/local/bin/composer.phar dump-autolode” for ubuntu

in your case “<composer_dir>/composer.phar dump-auto lode

On command line :- php artisan migrate:reset (for reset all migration)

Page 11: Laravel Beginners Tutorial 2

11 Author : Vikas Chauhan

Exercise4

Add Data Into Table Using Migration & Artisan

Page 12: Laravel Beginners Tutorial 2

12 Author : Vikas Chauhan

On command line :- php artisan migrate: make add_authors (create a file in migration for add data in authors table)

<project_dir>/ app/ database/ migration/

2013_08_07_102350_add_authors.php :-

That php file contain two function up() & down(). up() function is used for add data into table and down() function is

used for delete data from table. For example :-

Page 13: Laravel Beginners Tutorial 2

13 Author : Vikas Chauhan

class AddAuthors extends Migration

{

public function up() {

DB::table('authors')->insert(array(

'name'=>'vikas chauhan',

'bio'=>'vikas chauhan is a good developer','created_at'=>date('y-m-d H:m:s'),'updated_at'=>date('y-m-d H:m:s')));

}

public function down() {

DB::table('authors')->where('name','=','vikas chauhan')->delete();}

}

Page 14: Laravel Beginners Tutorial 2

14 Author : Vikas Chauhan

On command line :- “php artisan migrate” (for perform action on up function)

On command line :- “php artisan migrate: rollback” (for perform action on down function)

If you will see fatal error while you rollback the migration :-

on command line :- “var/local/bin/composer.phar dump-autolode” for ubuntu

in your case “<composer_dir>/composer.phar dump-auto lode

On command line :- php artisan migrate:reset (for reset all migration)

Page 15: Laravel Beginners Tutorial 2

15 Author : Vikas Chauhan

Thanks & Regards,Contact to – Vikas Chauhan

Email ID – [email protected]

Phone – (080) 41155974