1 of 50

Coding PHP with

2 of 50

Why to use Laravel

> Having fun with quick coding > Artisan CLI

> Easy to install with Composer > ORM

> Excellent documentation > Template Engine

> Understandable structure > Using OOP well

> MVC > Own Security

> Full routing > Community & Support

3 of 50

What will we discuss

> Installation > Blade Template Engine

> Directory Structure > Migration and Seeding

> Configuration > Database & Eloquent ORM

> Artisan CLI > Authentication & Security

> Routing > Localization & Validation

> Controllers > Resources to learn

4 of 50

Installation

Installing Composer

Going to directory where we want to create the project

Creating a new project called gdgistanbul

$ php composer.phar create-project laravel/laravel gdgistanbul --prefer-dist

5 of 50

Directory Structure

PS: Other files (css files, images, etc) can be stored in public folder which placed in your root directory of app.

1. Configuration files here

2. Controllers (MVC)

3. Database, migrations and seeds here

4. Models (MVC)

5. Views (MVC)

6. Routing are made in this file

6 of 50

Configuration

An example for general configuration file of application (config/app.php)

7 of 50

Configuration

An example for database configuration file (config/database.php)

Make sure you have installed the PDO driver of using database!

8 of 50

Artisan CLI

Listing all artisan commands

Running the development environment

Listing routes which you have determined in routes.php

9 of 50

Artisan CLI

Creating a table to migrate

Making a controller. Parameters can be find by (php artisan list)

Migrating all created migrations

10 of 50

MVC

11 of 50

Routing

URL rewrite module must be activated!

12 of 50

Controllers

13 of 50

Blade Template Engine

14 of 50

Blade Template Engine

15 of 50

Blade Template Engine

16 of 50

Migration and Seeding

First, let’s create a new table called TABLENAME

17 of 50

Migration and Seeding

Next, we define features of table

18 of 50

Migration and Seeding

Table created. Let’s insert a default data.

19 of 50

Migration and Seeding

Table created. Let’s migrate all migrations.

Finally, we seed our new table.

20 of 50

Database and Eloquent ORM

Getting all results from SELECT * FROM TABLENAME;

21 of 50

Database and Eloquent ORM

Getting first result from SELECT * FROM TABLENAME;

22 of 50

Database and Eloquent ORM

Using WHERE statement with Query Builder

23 of 50

Database and Eloquent ORM

COUNT, MAX, MIN, AVERAGE and SUM

24 of 50

Database and Eloquent ORM

INSERT INTO TABLENAME (username,address,age,birthdate) VALUES.....

25 of 50

Database and Eloquent ORM

UPDATE TABLENAME SET username=’newuser’, ..... WHERE id=$whichuser

26 of 50

Database and Eloquent ORM

DELETE FROM TABLENAME WHERE id=$whichuser

27 of 50

Database and Eloquent ORM

What the hell this query builder?! I wanna use classic SQL!

28 of 50

Database and Eloquent ORM

What about Eloquent?

29 of 50

Database and Eloquent ORM

First, we define an Eloquent model

30 of 50

Database and Eloquent ORM

SELECT statements by using Eloquent

31 of 50

Database and Eloquent ORM

INSERT statement by using Eloquent

32 of 50

Database and Eloquent ORM

UPDATE statement by using Eloquent

33 of 50

Database and Eloquent ORM

DELETE statement by using Eloquent

34 of 50

Authentication and Security

When you use HASH algorithm to generate and use passwords just as...

Laravel generates a password like that:

$2y$10$n/k5A/5Qry0WeG/SVXCpqusngR6FcVkCh68/eJJ7rdinsKggTENPe

35 of 50

Authentication and Security

You can also verify this hashed text:

36 of 50

Authentication and Security

How to log a user into system

37 of 50

Authentication and Security

Verifying if a user logged in or not

38 of 50

Authentication and Security

How to get information of logged in user

39 of 50

Authentication and Security

And log the user out

40 of 50

Localization

Language folder

41 of 50

Localization

All languages will be created here as folders

42 of 50

Localization

43 of 50

Localization

Changing app language

http://localhost/gdgistanbul/set-language/en or http://localhost/gdgistanbul/set-language/tr

44 of 50

Localization

Using values of activated language

45 of 50

Validation

46 of 50

Validation

We have determined rules. Now checking if it failed or not.

47 of 50

Resources to Learn

Laravel Documentation.

http://laravel.com/docs

Code Happy book.

Dayle Rees

Stackoverflow.

http://stackoverflow.com

Laravel Schema

Designer.

http://laravelsd.com

48 of 50

Questions?

49 of 50

Halil Kaya

halil@gdgistanbul.com www.halilkaya.net @HalilKaya

50 of 50

Thank you...