SlideShare a Scribd company logo
Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
Web Services
with Laravel
Abuzer Firdousi | SE
Web Services with Laravel
Content: • Laravel Philosophy
• Requirement
• Installation
• Basic Routing
• Requests & Input
• Request Lifecycle
• Controller
• Controller Filters
• RESTful Controllers
• Database Model using Eloquent ORM
• Creating A Migration
• Code Example
• Questions
Abuzer Firdousi
Abuzer Firdousi
Laravel Philosophy
Laravel is a web application framework with expressive, elegant syntax. We believe development
must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out
of development by easing common tas
•ROR
•ASP.NET MVC
•Sinatra (Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort)
Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications.
Laravel, the elegant PHP framework for web artisans
Abuzer Firdousi
Server Requirements
The Laravel framework has a few system requirements:
•PHP >= 5.3.7
•MCrypt PHP Extension
As of PHP 5.5, some OS distributions may require you to manually install the PHP JSON extension.
When using Ubuntu, this can be done via apt-get install php5-json.
MCrypt:
1.aptitude install php5-mcrypt
2.echo extension=php_mcrypt.so >> /etc/php5/apache2/php.ini
3. /etc/init.d/apache2 restart
Abuzer Firdousi
Installation
Laravel utilizes Composer to manage its dependencies. First, download a copy of the
composer.phar.
Via Composer Create-Project
You may install Laravel by issuing the Composer create-project command in your terminal:
composer create-project laravel/laravel --prefer-dist
Via Download
Once Composer is installed, download the latest version of the Laravel framework and extract its
contents into a directory on your server. Next, in the root of your Laravel application, run the php
composer.phar install (or composer install) command to install all of the framework's
dependencies. This process requires Git to be installed on the server to successfully complete
the installation.
If you want to update the Laravel framework, you may issue the php composer.phar update
command.
Laravel provides a server, and we can run the server with “php artisan* serve”
* command-line interface, a powerful Symfony Console component
Abuzer Firdousi
Basic Routing
Most of the routes for your application will be defined in the app/routes.php file. The simplest
Laravel routes consist of a URI and a Closure callback.
Basic GET Route:
Route::get('/', function()
{
return 'Hello World';
});
Basic POST Route:
Route::post('foo/bar', function()
{
return 'Hello World';
});
Abuzer Firdousi
Route Parameters
Route Parameters:
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
Optional Route Parameters:
Route::get('user/{name?}', function($name = null)
{
return $name;
});
Throwing 404 Errors:
There are two ways to manually trigger a 404 error from a route. First, you may use the App::abort
method:
App::abort(404);
Abuzer Firdousi
Requests & Input
Retrieving An Input Value
$name = Input::get('name');
Retrieving A Default Value If The Input Value Is Absent
$name = Input::get('name', Abuzer);
Getting All Input For The Request
$input = Input::all();
Abuzer Firdousi
Request Life Cycle
The Laravel request lifecycle is fairly simple. A request enters your application and is dispatched
to the appropriate route or controller. The response from that route is then sent back to the
browser and displayed on the screen. Sometimes you may wish to do some processing before or
after your routes are actually called. There are several opportunities to do this, two of which are
"start" files and application events.
Abuzer Firdousi
Controllers
Instead of defining all of your route-level logic in a single routes.php file, you may wish to
organize this behavior using Controller classes. Controllers can group related route logic into a
class, as well as take advantage of more advanced framework features such as automatic
dependency injection.
Controllers are typically stored in the app/controllers directory, and this directory is registered in
the class map option of your composer.json file by default.
Here is an example of a basic controller class:
class UserController extends BaseController {
/** * Show the profile for the given user. */
public function showProfile($id)
{
$user = User::find($id); //
return Response::json( array('user' => $user) );
}
}
Abuzer Firdousi
Controllers and Routes
All controllers should extend the BaseController class. The BaseController is also stored in the
app/controllers directory, and may be used as a place to put shared controller logic. The
BaseController extends the framework's Controller class. Now, We can route to this controller
action like so:
Route::get('user/{id}', 'UserController@showProfile');
If you choose to nest or organize your controller using PHP namespaces, simply use the fully
qualified class name when defining the route:
Route::get('foo', 'NamespaceFooController@method');
You may also specify names on controller routes:
Route::get('foo', array('uses' => 'FooController@method', 'as' => 'name'));
Abuzer Firdousi
Controller Filters
Filters may be specified on controller routes similar to "regular" routes: ( Kind of Request
INTERCEPTOR)
Route::get('profile', array('before' => 'auth',
'uses' => 'UserController@showProfile'));
However, you may also specify filters from within your controller:
class UserController extends BaseController {
/** * Instantiate a new UserController instance. */
public function __construct()
{
$this->beforeFilter('auth', array('except' => 'getLogin'));
$this->afterFilter('log', array('only' =>
array('fooAction', 'barAction')));
}
}
Abuzer Firdousi
RESTful Controllers
Laravel allows you to easily define a single route to handle every action in a controller using
simple, REST naming conventions. First, define the route using the Route::controller method:
Defining A RESTful Controller
Route::controller('users', 'UserController');
The controller method accepts two arguments. The first is the base URI the controller handles,
while the second is the class name of the controller. Next, just add methods to your controller,
prefixed with the HTTP verb they respond to:
class UserController extends BaseController {
public function getIndex()
{ // }
public function postIndex()
{ // }
public function putIndex()
{ // }
public function deleteIndex()
{ // }
}
Abuzer Firdousi
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.
Before getting started, be sure to configure a database connection in app/config/database.php.
class User extends Eloquent {
protected $table = 'my_users';
}
Retrieving All Models
$users = User::all();
Retrieving A Record By Primary Key
$user = User::find(1);
Querying Using Eloquent Models
$users = User::where('votes', '>', 100)->take(10)->get();
foreach ($users as $user)
var_dump($user->name);
Abuzer Firdousi
Example
Questions ?
Abuzer Firdousi

More Related Content

What's hot (20)

PPTX
Introduction to laravel framework
Ahmad Fatoni
 
PDF
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
PDF
Why Laravel?
Jonathan Goode
 
PPTX
Laravel Beginners Tutorial 1
Vikas Chauhan
 
PPTX
Introduction to Laravel Framework (5.2)
Viral Solani
 
PPTX
Laravel for Web Artisans
Raf Kewl
 
PPTX
Intro to Laravel
Azukisoft Pte Ltd
 
PPTX
Laravel 5
Sudip Simkhada
 
PPTX
API Development with Laravel
Michael Peacock
 
PPTX
Laravel ppt
Mayank Panchal
 
PPTX
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
PDF
What's New In Laravel 5
Darren Craig
 
PDF
Hello World on Slim Framework 3.x
Ryan Szrama
 
PPTX
Laravel Beginners Tutorial 2
Vikas Chauhan
 
PDF
Laravel 5 In Depth
Kirk Bushell
 
PPTX
Laravel introduction
Simon Funk
 
PDF
Laravel presentation
Toufiq Mahmud
 
PDF
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
PDF
ACL in CodeIgniter
mirahman
 
PDF
Symfony3 w duecie z Vue.js
X-Coding IT Studio
 
Introduction to laravel framework
Ahmad Fatoni
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
Why Laravel?
Jonathan Goode
 
Laravel Beginners Tutorial 1
Vikas Chauhan
 
Introduction to Laravel Framework (5.2)
Viral Solani
 
Laravel for Web Artisans
Raf Kewl
 
Intro to Laravel
Azukisoft Pte Ltd
 
Laravel 5
Sudip Simkhada
 
API Development with Laravel
Michael Peacock
 
Laravel ppt
Mayank Panchal
 
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
What's New In Laravel 5
Darren Craig
 
Hello World on Slim Framework 3.x
Ryan Szrama
 
Laravel Beginners Tutorial 2
Vikas Chauhan
 
Laravel 5 In Depth
Kirk Bushell
 
Laravel introduction
Simon Funk
 
Laravel presentation
Toufiq Mahmud
 
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
ACL in CodeIgniter
mirahman
 
Symfony3 w duecie z Vue.js
X-Coding IT Studio
 

Viewers also liked (7)

PPS
Conceptmap, mindmap
illeso
 
PDF
Introduction to Laravel
Eli Wheaton
 
PPTX
Service Oriented Architecture
Mohamed Zaytoun
 
PDF
Dependency Injection in Laravel
HAO-WEN ZHANG
 
PDF
Service-Oriented Architecture
Samantha Geitz
 
PDF
Service Oriented Architecture & Beyond
Imesh Gunaratne
 
PDF
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
ZendCon
 
Conceptmap, mindmap
illeso
 
Introduction to Laravel
Eli Wheaton
 
Service Oriented Architecture
Mohamed Zaytoun
 
Dependency Injection in Laravel
HAO-WEN ZHANG
 
Service-Oriented Architecture
Samantha Geitz
 
Service Oriented Architecture & Beyond
Imesh Gunaratne
 
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
ZendCon
 
Ad

Similar to Web service with Laravel (20)

PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
DOCX
Laravel
Ilham Pratama
 
PDF
Laravel 5 New Features
Joe Ferguson
 
PDF
MidwestPHP 2016 - Adventures in Laravel 5
Joe Ferguson
 
PDF
Meetup 2022 - APIs with Quarkus.pdf
Red Hat
 
PPT
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 
PPTX
Laravel overview
Obinna Akunne
 
PPTX
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
annalakshmi35
 
PDF
Web Development with Laravel 5
Soheil Khodayari
 
PPTX
23003468463PPT.pptx
annalakshmi35
 
PDF
Building web framework with Rack
sickill
 
PPTX
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
PDF
Express node js
Yashprit Singh
 
KEY
How and why i roll my own node.js framework
Ben Lin
 
ODP
Laravel 5.3 - Web Development Php framework
Swapnil Tripathi ( Looking for new challenges )
 
PDF
laravel-interview-questions.pdf
AnuragMourya8
 
PDF
Create Home Directories on Storage Using WFA and ServiceNow integration
Rutul Shah
 
PDF
Apache - Quick reference guide
Joseph's WebSphere Library
 
PDF
Go swagger tutorial how to create golang api documentation using go swagger (1)
Katy Slemon
 
PPT
Laravel intallation
sandhya kumari
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
Laravel
Ilham Pratama
 
Laravel 5 New Features
Joe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
Joe Ferguson
 
Meetup 2022 - APIs with Quarkus.pdf
Red Hat
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 
Laravel overview
Obinna Akunne
 
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
annalakshmi35
 
Web Development with Laravel 5
Soheil Khodayari
 
23003468463PPT.pptx
annalakshmi35
 
Building web framework with Rack
sickill
 
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
Express node js
Yashprit Singh
 
How and why i roll my own node.js framework
Ben Lin
 
Laravel 5.3 - Web Development Php framework
Swapnil Tripathi ( Looking for new challenges )
 
laravel-interview-questions.pdf
AnuragMourya8
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Rutul Shah
 
Apache - Quick reference guide
Joseph's WebSphere Library
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Katy Slemon
 
Laravel intallation
sandhya kumari
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 

Web service with Laravel

  • 1. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  • 2. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products. Web Services with Laravel Abuzer Firdousi | SE
  • 3. Web Services with Laravel Content: • Laravel Philosophy • Requirement • Installation • Basic Routing • Requests & Input • Request Lifecycle • Controller • Controller Filters • RESTful Controllers • Database Model using Eloquent ORM • Creating A Migration • Code Example • Questions Abuzer Firdousi
  • 4. Abuzer Firdousi Laravel Philosophy Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tas •ROR •ASP.NET MVC •Sinatra (Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort) Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. Laravel, the elegant PHP framework for web artisans
  • 5. Abuzer Firdousi Server Requirements The Laravel framework has a few system requirements: •PHP >= 5.3.7 •MCrypt PHP Extension As of PHP 5.5, some OS distributions may require you to manually install the PHP JSON extension. When using Ubuntu, this can be done via apt-get install php5-json. MCrypt: 1.aptitude install php5-mcrypt 2.echo extension=php_mcrypt.so >> /etc/php5/apache2/php.ini 3. /etc/init.d/apache2 restart
  • 6. Abuzer Firdousi Installation Laravel utilizes Composer to manage its dependencies. First, download a copy of the composer.phar. Via Composer Create-Project You may install Laravel by issuing the Composer create-project command in your terminal: composer create-project laravel/laravel --prefer-dist Via Download Once Composer is installed, download the latest version of the Laravel framework and extract its contents into a directory on your server. Next, in the root of your Laravel application, run the php composer.phar install (or composer install) command to install all of the framework's dependencies. This process requires Git to be installed on the server to successfully complete the installation. If you want to update the Laravel framework, you may issue the php composer.phar update command. Laravel provides a server, and we can run the server with “php artisan* serve” * command-line interface, a powerful Symfony Console component
  • 7. Abuzer Firdousi Basic Routing Most of the routes for your application will be defined in the app/routes.php file. The simplest Laravel routes consist of a URI and a Closure callback. Basic GET Route: Route::get('/', function() { return 'Hello World'; }); Basic POST Route: Route::post('foo/bar', function() { return 'Hello World'; });
  • 8. Abuzer Firdousi Route Parameters Route Parameters: Route::get('user/{id}', function($id) { return 'User '.$id; }); Optional Route Parameters: Route::get('user/{name?}', function($name = null) { return $name; }); Throwing 404 Errors: There are two ways to manually trigger a 404 error from a route. First, you may use the App::abort method: App::abort(404);
  • 9. Abuzer Firdousi Requests & Input Retrieving An Input Value $name = Input::get('name'); Retrieving A Default Value If The Input Value Is Absent $name = Input::get('name', Abuzer); Getting All Input For The Request $input = Input::all();
  • 10. Abuzer Firdousi Request Life Cycle The Laravel request lifecycle is fairly simple. A request enters your application and is dispatched to the appropriate route or controller. The response from that route is then sent back to the browser and displayed on the screen. Sometimes you may wish to do some processing before or after your routes are actually called. There are several opportunities to do this, two of which are "start" files and application events.
  • 11. Abuzer Firdousi Controllers Instead of defining all of your route-level logic in a single routes.php file, you may wish to organize this behavior using Controller classes. Controllers can group related route logic into a class, as well as take advantage of more advanced framework features such as automatic dependency injection. Controllers are typically stored in the app/controllers directory, and this directory is registered in the class map option of your composer.json file by default. Here is an example of a basic controller class: class UserController extends BaseController { /** * Show the profile for the given user. */ public function showProfile($id) { $user = User::find($id); // return Response::json( array('user' => $user) ); } }
  • 12. Abuzer Firdousi Controllers and Routes All controllers should extend the BaseController class. The BaseController is also stored in the app/controllers directory, and may be used as a place to put shared controller logic. The BaseController extends the framework's Controller class. Now, We can route to this controller action like so: Route::get('user/{id}', 'UserController@showProfile'); If you choose to nest or organize your controller using PHP namespaces, simply use the fully qualified class name when defining the route: Route::get('foo', 'NamespaceFooController@method'); You may also specify names on controller routes: Route::get('foo', array('uses' => 'FooController@method', 'as' => 'name'));
  • 13. Abuzer Firdousi Controller Filters Filters may be specified on controller routes similar to "regular" routes: ( Kind of Request INTERCEPTOR) Route::get('profile', array('before' => 'auth', 'uses' => 'UserController@showProfile')); However, you may also specify filters from within your controller: class UserController extends BaseController { /** * Instantiate a new UserController instance. */ public function __construct() { $this->beforeFilter('auth', array('except' => 'getLogin')); $this->afterFilter('log', array('only' => array('fooAction', 'barAction'))); } }
  • 14. Abuzer Firdousi RESTful Controllers Laravel allows you to easily define a single route to handle every action in a controller using simple, REST naming conventions. First, define the route using the Route::controller method: Defining A RESTful Controller Route::controller('users', 'UserController'); The controller method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller. Next, just add methods to your controller, prefixed with the HTTP verb they respond to: class UserController extends BaseController { public function getIndex() { // } public function postIndex() { // } public function putIndex() { // } public function deleteIndex() { // } }
  • 15. Abuzer Firdousi 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. Before getting started, be sure to configure a database connection in app/config/database.php. class User extends Eloquent { protected $table = 'my_users'; } Retrieving All Models $users = User::all(); Retrieving A Record By Primary Key $user = User::find(1); Querying Using Eloquent Models $users = User::where('votes', '>', 100)->take(10)->get(); foreach ($users as $user) var_dump($user->name);