Coding PHP with
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
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
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
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
Configuration
An example for general configuration file of application (config/app.php)
Configuration
An example for database configuration file (config/database.php)
Make sure you have installed the PDO driver of using database!
Artisan CLI
Listing all artisan commands
Running the development environment
Listing routes which you have determined in routes.php
Artisan CLI
Creating a table to migrate
Making a controller. Parameters can be find by (php artisan list)
Migrating all created migrations
MVC
Routing
URL rewrite module must be activated!
Controllers
Blade Template Engine
Blade Template Engine
Blade Template Engine
Migration and Seeding
First, let’s create a new table called TABLENAME
Migration and Seeding
Next, we define features of table
Migration and Seeding
Table created. Let’s insert a default data.
Migration and Seeding
Table created. Let’s migrate all migrations.
Finally, we seed our new table.
Database and Eloquent ORM
Getting all results from SELECT * FROM TABLENAME;
Database and Eloquent ORM
Getting first result from SELECT * FROM TABLENAME;
Database and Eloquent ORM
Using WHERE statement with Query Builder
Database and Eloquent ORM
COUNT, MAX, MIN, AVERAGE and SUM
Database and Eloquent ORM
INSERT INTO TABLENAME (username,address,age,birthdate) VALUES.....
Database and Eloquent ORM
UPDATE TABLENAME SET username=’newuser’, ..... WHERE id=$whichuser
Database and Eloquent ORM
DELETE FROM TABLENAME WHERE id=$whichuser
Database and Eloquent ORM
What the hell this query builder?! I wanna use classic SQL!
Database and Eloquent ORM
What about Eloquent?
Database and Eloquent ORM
First, we define an Eloquent model
Database and Eloquent ORM
SELECT statements by using Eloquent
Database and Eloquent ORM
INSERT statement by using Eloquent
Database and Eloquent ORM
UPDATE statement by using Eloquent
Database and Eloquent ORM
DELETE statement by using Eloquent
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
Authentication and Security
You can also verify this hashed text:
Authentication and Security
How to log a user into system
Authentication and Security
Verifying if a user logged in or not
Authentication and Security
How to get information of logged in user
Authentication and Security
And log the user out
Localization
Language folder
Localization
All languages will be created here as folders
Localization
Localization
Changing app language
http://localhost/gdgistanbul/set-language/en or http://localhost/gdgistanbul/set-language/tr
Localization
Using values of activated language
Validation
Validation
We have determined rules. Now checking if it failed or not.
Resources to Learn
Laravel Documentation.
http://laravel.com/docs
Code Happy book.
Dayle Rees
Stackoverflow.
http://stackoverflow.com
Laravel Schema
Designer.
http://laravelsd.com
Questions?
Halil Kaya
halil@gdgistanbul.com www.halilkaya.net @HalilKaya
Thank you...