SlideShare a Scribd company logo
LARAVEL 5
What is Laravel?
• PHP Framework
• Most popular on Github
• MVC Architecture
• MIT License
Why Laravel?
• Composer
• Community
• Code Construction
@bukhorimuhammad
Less Talking, 

More Coding
Requirements
• Composer
• Local server (with XAMPP, WAMP, MAMP, etc)
• PHP 5.4+
• Mcrypt, OpenSSL, Mbstring, Tokenizer & PHP
JSON extension
COMPOSER
Composer is a tool for dependency management in PHP. It allows
you to declare the dependent libraries your project needs and it will
install them in your project for you.


https://getcomposer.org
UNIX : curl -sS https://getcomposer.org/installer | php
WIN : https://getcomposer.org/Composer-Setup.exe
Installing Laravel
Composer Global :
composer create-project laravel/laravel —-
prefer-dist foldername
Composer Local :
php /path/to/composer.phar create-project
laravel/laravel --prefer-dist foldername
Fix Folder Permission
• Set storage folder to be writable (777)
• Set vendor folder to be writable (777)
Getting to know Laravel 5
@bukhorimuhammad
Laravel Concepts
Laravel Artisan
Artisan is the name of the command-line interface included with
Laravel. It provides a number of helpful commands for your use
while developing your application. It is driven by the powerful
Symfony Console component.
php artisan list : 

list all available artisan command
php artisan help [command] : 

help information for each command
http://laravel.com/docs/5.0/artisan
Laravel Routing
Routing is the process of taking a URI endpoint (that part of the
URI which comes after the base URL) and decomposing it into
parameters to determine which module, controller, and action of
that controller should receive the request.
http://laravel.com/docs/5.0/routing
Route::get('/', function()
{
return 'Hello World';
});
Route::post('foo/bar', function()
{
return 'Hello World';
});
Route::any('foo', function()
{
return 'Hello World';
});
Route::match(['put', 'delete'], '/',
function() {
return 'Hello World';
});
HTTP METHODS
• GET : used to retrieve (or read) a representation of a
resource. Return 200 OK or 404 NOT FOUND or 400
BAD REQUEST
• POST : used to create new resources. Return 201 OK
or 404 NOT FOUND
• PUT : used to update existing resource. Return 200 OK
or 204 NO CONTENT or 404 NOT FOUND
• DELETE : used to delete existing resource. Return 200
OK or 404 NOT FOUND
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
CODING TIME!
• Open app/Http/routes.php
• Insert couple of routes
Route::get('tesget', function()
{
return 'Hello World';
});
Route::post('tespost', function()
{
return 'Hello World';
});
Route::any('tesany', function()
{
return 'Hello World';
});
Route::match(['put', 'delete'], 

'tesmatch', function() {
return 'Hello World';
});
CODING TIME!
• Insert -> Route::resource(‘welcome’,
‘WelcomeController');
• Go to terminal / command line.
• Type php artisan route:list
Laravel Controller
Instead of defining all of your request handling logic in a single
routes.php file, you may wish to organize this behavior using
Controller classes. Controllers can group related HTTP request
handling logic into a class. Controllers are typically stored in the
app/Http/Controllers directory.
http://laravel.com/docs/5.0/controllers
CODING TIME!
• go to app/Http/Controller
• create new Controller class (DummyController.php)
• go to app/Http/routes.php
• insert -> Route::get(‘dummy’,
‘DummyController@index‘);
CODING TIME!
• php artisan make:controller Dummy2Controller
• go to app/Http/routes.php
• insert -> Route::resource(‘dummy2’,
‘Dummy2Controller');
Laravel Model
A Model should contain all of the Business Logic of your
application. Or in other words, how the application interacts with
the database.
http://laravel.com/docs/5.0/database
The database configuration file is config/database.php
DB::select('select * from users where id = :id', ['id' => 1]);
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);
DB::update('update users set votes = 100 where name = ?', ['John']);
DB::delete('delete from users');
DB::statement('drop table users');
Query Builder
The database query builder provides a convenient, fluent
interface to creating and running database queries. It can be
used to perform most database operations in your application,
and works on all supported database systems.
http://laravel.com/docs/5.0/queries
DB::table('users')->get();
DB::table('users')->insert(
['email' => 'john@example.com', 'votes' => 0]
);
DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
DB::table('users')->where('votes', '<', 100)->delete();
Eloquent ORM
The Eloquent ORM included with Laravel provides a beautiful,
simple ActiveRecord implementation for working with your
database. Each database table has a corresponding "Model"
which is used to interact with that table.
http://laravel.com/docs/5.0/eloquent
class User extends Model {}
php artisan make:model User
class User extends Model {
protected $table = 'my_users';
}
$users = User::all();
$model = User::where('votes', '>', 100)->firstOrFail();
Schema Builder
The Laravel Schema class provides a database agnostic way of
manipulating tables. It works well with all of the databases
supported by Laravel, and has a unified API across all of these
systems.
http://laravel.com/docs/5.0/schema
Schema::create('users', function($table)
{
$table->increments('id');
});
Schema::rename($from, $to);
Schema::drop('users');
Migrations & Seeding
Migrations are a type of version control for your database. They
allow a team to modify the database schema and stay up to date
on the current schema state. Migrations are typically paired with
the Schema Builder to easily manage your application's schema.
http://laravel.com/docs/5.0/migrations
php artisan make:migration create_users_table
class UserTableSeeder extends Seeder {
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'foo@bar.com']);
}
}
php artisan db:seed
php artisan migrate --force
CODING TIME!
• go to env.example, rename it to .env
• set DB_HOST=localhost
• set DB_DATABASE=yourdbname
• set DB_USERNAME=yourdbusername
• set DB_PASSWORD=yourdbpassword
CODING TIME!
run php artisan make:migration create_sample_table
run php artisan migrate
CODING TIME!
create SampleTableSeeder.php
run php artisan db:seed
run composer dump-autoload
CODING TIME!
run php artisan make:model Sample
run composer migrate
edit app/Sample.php
Laravel View
Views contain the HTML served by your application, and serve
as a convenient method of separating your controller and
domain logic from your presentation logic. Views are stored in
the resources/views directory.
http://laravel.com/docs/5.0/views
CODING TIME!
create resources/views/sample.php
create app/Http/controllers/SampleController.php
register the route in app/Http/routes.php

More Related Content

PDF
Why Laravel?
PDF
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
PPTX
Introduction to Laravel Framework (5.2)
PPTX
Workshop Laravel 5.2
PPTX
Introduction to laravel framework
PPTX
Laravel for Web Artisans
PDF
What's New In Laravel 5
PDF
Laravel 5 Annotations: RESTful API routing
Why Laravel?
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Introduction to Laravel Framework (5.2)
Workshop Laravel 5.2
Introduction to laravel framework
Laravel for Web Artisans
What's New In Laravel 5
Laravel 5 Annotations: RESTful API routing

What's hot (20)

PPTX
Intro to Laravel
PPTX
A introduction to Laravel framework
PPTX
Laravel Beginners Tutorial 1
PDF
Web Development with Laravel 5
PDF
Knowing Laravel 5 : The most popular PHP framework
PPTX
Laravel 5
PDF
Laravel presentation
PPTX
Laravel - Website Development in Php Framework.
PDF
Laravel Introduction
PPTX
10 Laravel packages everyone should know
ODP
Presentation laravel 5 4
PPT
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
PDF
Laravel 5.4
PDF
All Aboard for Laravel 5.1
PDF
Laravel Restful API and AngularJS
PPTX
Laravel Beginners Tutorial 2
PPTX
API Development with Laravel
PPTX
Laravel ppt
PDF
All the Laravel things: up and running to making $$
PPTX
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
Intro to Laravel
A introduction to Laravel framework
Laravel Beginners Tutorial 1
Web Development with Laravel 5
Knowing Laravel 5 : The most popular PHP framework
Laravel 5
Laravel presentation
Laravel - Website Development in Php Framework.
Laravel Introduction
10 Laravel packages everyone should know
Presentation laravel 5 4
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel 5.4
All Aboard for Laravel 5.1
Laravel Restful API and AngularJS
Laravel Beginners Tutorial 2
API Development with Laravel
Laravel ppt
All the Laravel things: up and running to making $$
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
Ad

Similar to Getting to know Laravel 5 (20)

PPTX
REST APIs in Laravel 101
PDF
Web services with laravel
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
PPT
Web service with Laravel
PDF
Introduction to Laravel
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
KEY
Supa fast Ruby + Rails
PDF
Building web framework with Rack
PDF
CakePHP
PPTX
Laravel Meetup
PPTX
PHP from soup to nuts Course Deck
PDF
Rails 4.0
PPTX
Lecture 2_ Intro to laravel.pptx
KEY
Wider than rails
PPTX
Laravel 5
PDF
ITB2016 - Building ColdFusion RESTFul Services
KEY
Using and scaling Rack and Rack-based middleware
PDF
Laravel intake 37 all days
PPTX
Day02 a pi.
REST APIs in Laravel 101
Web services with laravel
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Web service with Laravel
Introduction to Laravel
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
Supa fast Ruby + Rails
Building web framework with Rack
CakePHP
Laravel Meetup
PHP from soup to nuts Course Deck
Rails 4.0
Lecture 2_ Intro to laravel.pptx
Wider than rails
Laravel 5
ITB2016 - Building ColdFusion RESTFul Services
Using and scaling Rack and Rack-based middleware
Laravel intake 37 all days
Day02 a pi.
Ad

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
top salesforce developer skills in 2025.pdf
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
Introduction to Artificial Intelligence
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
PDF
How to Confidently Manage Project Budgets
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
Understanding Forklifts - TECH EHS Solution
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
Softaken Excel to vCard Converter Software.pdf
PTS Company Brochure 2025 (1).pdf.......
top salesforce developer skills in 2025.pdf
Materi_Pemrograman_Komputer-Looping.pptx
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Digital Strategies for Manufacturing Companies
Introduction to Artificial Intelligence
The Role of Automation and AI in EHS Management for Data Centers.pdf
How to Confidently Manage Project Budgets
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
A REACT POMODORO TIMER WEB APPLICATION.pdf
Best Practices for Rolling Out Competency Management Software.pdf
medical staffing services at VALiNTRY
AI in Product Development-omnex systems

Getting to know Laravel 5

  • 2. What is Laravel? • PHP Framework • Most popular on Github • MVC Architecture • MIT License
  • 3. Why Laravel? • Composer • Community • Code Construction
  • 5. Requirements • Composer • Local server (with XAMPP, WAMP, MAMP, etc) • PHP 5.4+ • Mcrypt, OpenSSL, Mbstring, Tokenizer & PHP JSON extension
  • 6. COMPOSER Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you. 
 https://getcomposer.org UNIX : curl -sS https://getcomposer.org/installer | php WIN : https://getcomposer.org/Composer-Setup.exe
  • 7. Installing Laravel Composer Global : composer create-project laravel/laravel —- prefer-dist foldername Composer Local : php /path/to/composer.phar create-project laravel/laravel --prefer-dist foldername
  • 8. Fix Folder Permission • Set storage folder to be writable (777) • Set vendor folder to be writable (777)
  • 11. Laravel Artisan Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component. php artisan list : 
 list all available artisan command php artisan help [command] : 
 help information for each command http://laravel.com/docs/5.0/artisan
  • 12. Laravel Routing Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request. http://laravel.com/docs/5.0/routing Route::get('/', function() { return 'Hello World'; }); Route::post('foo/bar', function() { return 'Hello World'; }); Route::any('foo', function() { return 'Hello World'; }); Route::match(['put', 'delete'], '/', function() { return 'Hello World'; });
  • 13. HTTP METHODS • GET : used to retrieve (or read) a representation of a resource. Return 200 OK or 404 NOT FOUND or 400 BAD REQUEST • POST : used to create new resources. Return 201 OK or 404 NOT FOUND • PUT : used to update existing resource. Return 200 OK or 204 NO CONTENT or 404 NOT FOUND • DELETE : used to delete existing resource. Return 200 OK or 404 NOT FOUND http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
  • 14. CODING TIME! • Open app/Http/routes.php • Insert couple of routes Route::get('tesget', function() { return 'Hello World'; }); Route::post('tespost', function() { return 'Hello World'; }); Route::any('tesany', function() { return 'Hello World'; }); Route::match(['put', 'delete'], 
 'tesmatch', function() { return 'Hello World'; });
  • 15. CODING TIME! • Insert -> Route::resource(‘welcome’, ‘WelcomeController'); • Go to terminal / command line. • Type php artisan route:list
  • 16. Laravel Controller Instead of defining all of your request handling logic in a single routes.php file, you may wish to organize this behavior using Controller classes. Controllers can group related HTTP request handling logic into a class. Controllers are typically stored in the app/Http/Controllers directory. http://laravel.com/docs/5.0/controllers
  • 17. CODING TIME! • go to app/Http/Controller • create new Controller class (DummyController.php) • go to app/Http/routes.php • insert -> Route::get(‘dummy’, ‘DummyController@index‘);
  • 18. CODING TIME! • php artisan make:controller Dummy2Controller • go to app/Http/routes.php • insert -> Route::resource(‘dummy2’, ‘Dummy2Controller');
  • 19. Laravel Model A Model should contain all of the Business Logic of your application. Or in other words, how the application interacts with the database. http://laravel.com/docs/5.0/database The database configuration file is config/database.php DB::select('select * from users where id = :id', ['id' => 1]); DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']); DB::update('update users set votes = 100 where name = ?', ['John']); DB::delete('delete from users'); DB::statement('drop table users');
  • 20. Query Builder The database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application, and works on all supported database systems. http://laravel.com/docs/5.0/queries DB::table('users')->get(); DB::table('users')->insert( ['email' => '[email protected]', 'votes' => 0] ); DB::table('users') ->where('id', 1) ->update(['votes' => 1]); DB::table('users')->where('votes', '<', 100)->delete();
  • 21. Eloquent ORM The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. http://laravel.com/docs/5.0/eloquent class User extends Model {} php artisan make:model User class User extends Model { protected $table = 'my_users'; } $users = User::all(); $model = User::where('votes', '>', 100)->firstOrFail();
  • 22. Schema Builder The Laravel Schema class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Laravel, and has a unified API across all of these systems. http://laravel.com/docs/5.0/schema Schema::create('users', function($table) { $table->increments('id'); }); Schema::rename($from, $to); Schema::drop('users');
  • 23. Migrations & Seeding Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema. http://laravel.com/docs/5.0/migrations php artisan make:migration create_users_table class UserTableSeeder extends Seeder { public function run() { DB::table('users')->delete(); User::create(['email' => '[email protected]']); } } php artisan db:seed php artisan migrate --force
  • 24. CODING TIME! • go to env.example, rename it to .env • set DB_HOST=localhost • set DB_DATABASE=yourdbname • set DB_USERNAME=yourdbusername • set DB_PASSWORD=yourdbpassword
  • 25. CODING TIME! run php artisan make:migration create_sample_table run php artisan migrate
  • 26. CODING TIME! create SampleTableSeeder.php run php artisan db:seed run composer dump-autoload
  • 27. CODING TIME! run php artisan make:model Sample run composer migrate edit app/Sample.php
  • 28. Laravel View Views contain the HTML served by your application, and serve as a convenient method of separating your controller and domain logic from your presentation logic. Views are stored in the resources/views directory. http://laravel.com/docs/5.0/views
  • 29. CODING TIME! create resources/views/sample.php create app/Http/controllers/SampleController.php register the route in app/Http/routes.php