SlideShare a Scribd company logo
Laravel intake 37 all days
Content
● History
● Composer
● Install Laravel
● Directory Structure
● Routing
● Blade Templating Engine
● Database & Eloquent
● Request Validation & Middleware
● Service Container
History
- DHH released first version of ruby on rails on 2004
- Some of php frameworks got inspired by RoR
- In 2010 taylor become dissatisfied with CodeIgniter as
They were slow to catch up new features like namesapces
History
- Laravel 1 (June 2011) included built in support for
(authentication - routing - models - views - ..)
- Laravel 2 (September 2011) included support for
(controllers - blade template engine - IOC - .. )
- Laravel 3 (February 2012) included support for
(CLI Artisan - events - migrations - bundles - ..)
History
- Laravel 4 (May 2013 ) taylor rewrote framework from
scratch and developed set of components under code name
Illuminate , and pulled majority of components from
symfony also included support for ( seeding - soft delete - ..)
- Laravel 5 (Feb 2015) new directory tree structure and
included support for (socialite - elixir - dotenv -...)
Composer
- Composer is a dependency manager like npm for node or
ruby gems for ruby .
- Download From here
https://getcomposer.org/download/
- Make composer globally
https://getcomposer.org/doc/00-intro.md#globally
Install Laravel
https://laravel.com/docs/master/installation#installing-laravel
Directory Structure
- Laravel Version 5.4 you will see :-
- app/ --> where your application go like ( models controllers)
- bootstrap/ --> files laravel uses to boot every time
- config/ --> configuration files like (database configuration)
- database/ --> where (migrations - seeds - factories) exist
- public/ --> directory where server points to it when serving
request it also contains (index.php)
- resources/ --> contains (views - Saas -Less files - ..)
- routes/ --> all routes definitions (Api - console -http)
Directory Structure
- storage/ --> where cache logs compiled files exist
- tests/ --> where unit & integration test exist
- vendor/ --> composer packages
- .env --> defines environments variables
- .env.example --> same as above ,it should be copied when
cloning other projects
- .gitattributes , .gitignore --> git configuration files
- artisan --> php script to run artisan commands
Directory Structure
- composer.json , composer.lock --> contains project
dependencies
- package.json --> like composer.json for frontend assets
- phpunit.xml --> configuration for php unit
- readme.md --> markdown for laravel introduction
- server.php --> it’s a server that emulate apache
mod_rewrite
- webpack.mix.js --> used for compiling and mixing frontend
assets
Routing
- Controller’s Method
Route::get(‘/posts’ , ‘PostsController@index’);
- Parameters
Route::get(‘/posts/{id}’ , ‘PostsController@edit’);
Routing
- Named Routes
Route::get(‘/posts’ , [
‘uses’ => ‘PostsController@index’,
‘as’ => ‘posts.index’
]);
more at https://laravel.com/docs/5.4/routing
Blade
- Blade is inspired by .NET’s Razor engine .
- echo data :- {{ $post }} instead of <?php echo $post ; ?>
- conditions :-
@if ($post->name == ‘firstPost’)
// do some stuff
@endif
Blade
- looping :-
@foreach($posts as $post) //do some stuff @endforeach
- inheritance :- @exnteds(‘layouts.master’)
- define sections :-
@section(‘content’)
<h1> hello from the content
@endsection
Blade
- printing sections :- @yield(‘content’)
- including :- @include(‘scripts’)
- Including with parameters :-
@include(‘post.form’,[‘method’ => ‘POST’])
more at https://laravel.com/docs/master/blade#introduction
Database & Eloquent
- Laravel ORM is called Eloquent
- Database configuration in .env file or from
config/database.php.
- Laravel migration helps in making database persistent across
multiple machines .
- DB facade used to form query builder object
Database & Eloquent
- $post = DB::table(‘posts’)->find(20); //finds a row with id =
20
- $posts = DB::table('posts')->get(); //get all rows in posts table
- $singlePost = DB::table(‘posts’)->where(‘name’ ,
‘FirstPost’)->get(); //where conditions to query
- $firstPost = DB::table(‘posts’)->first(); //gets the first row
Database & Eloquent
- DB::table(‘posts’)->insert(
[‘title’ => ‘first post title’ , ‘desc’ => ‘first post desc ‘]
); //inserting a row
- DB::table('posts')->where(‘id’ , 1)->delete(); //deletes a row
- DB::table(‘posts’)->where(‘id’ , 1)
->update( [ ‘title’ => ‘changed title post ] );
//update the post title only
Database & Eloquent
- php artisan make:model Post //create a new model class
- Laravel by default gets the plural name of model as a table
name and makes query based on that
- Post::all() //will search in posts table and get all rows
- Post::create([‘title’ => ‘first post’ , ‘desc’ => ‘desc post’);
//this will give a MassAssignmentException unless you
override $fillable
Database & Eloquent
- Post::find(25)->update([‘title’ => ‘update post title’)
//updates title for post with id 25
- Post::where(‘votes’, 23)->delete()
//deletes any post have votes with 23
Database & Eloquent
- To define a relation in Post model you will define a function in
the class for example i want to say post have many sections .
//in Post model class
public function sections ()
{ return $this->hasMany(Section::class);}
// in controller for example
$postSections = Post::find(23)->sections;
Database & Eloquent
- Remember that query results are collection objects
- More at Eloquent
https://laravel.com/docs/master/eloquent#introduction
- More at Collections
https://laravel.com/docs/master/collections#available-meth
ods
Request Validation
- Request Life Cycle :-
See index.php first it loads the composers’s autload file .
Then we bootstrap laravel application container and register
some basic service providers like Log Service provider
look at Illuminate/Foundation/Application.php constructor
method .
Finally we create instance of kernel to register providers and
take user request and process it through middlewares &
handle exception then return response
Request Validation
- In Controller :-
$this->validate( $request , [
‘title ‘ => ‘required ‘,
‘desc’ => ‘required|max:255’
] ,
[
‘title.required’ => ‘title is required to be filled ‘ ,
‘desc.max’ => ‘description max num of chars is 255 ‘
]);
Request Validation
- Another way with request file :-
php artisan make:request PostsStoreRequest
Then in authorize method make it return true .
After that define your rules in rules method .
- validation rules :-
https://laravel.com/docs/master/validation#available-validation-rules
- custom validation messages in request file :-
https://laravel.com/docs/master/validation#customizing-the-error-messages
Middleware
- It’s a series of layers around the application , every request
passes through middlewares .
- Middlewares can inspect the request to decorate or reject it
- Also middlewares can decorate the response .
- register the middlewares in app/Http/Kernel.php
- handle($request , ..) method where you handle the request and
choose to pass it for the next middleware or not .
Middleware
Service Container
- Other names for service container
( IOC container , DI container , Application container )
- Dependency Injection (DI) :-
Instead to make object instantiate it’s dependencies
internally , it will be passed from outside .
Service Container
- Class User {
function __construct ()
{
$mysqlConnection = new Mysql();
}
}
$user = new User(); // in this way object instantiated it’s
dependencies internally
Service Container
- Class User {
protected $dbConnection;
//DB is an interface to easily switch between different db drivers
function __construct (DB $db)
{
$this->dbConnection = $db;
}
}
$mysqlConnection = new Mysql();
$user = new User( $mysqlConnection ); // the user object dependencies
are passed from outside .
Service Container
- Service container in laravel responsible for binding &
resolving & AutoWiring
- Try this in controller :-
public function index (Request $request)
{
dd($request);
}
// so how does the $request prints an object without instantiating it !!?
Service Container
- In the previous example , the illuminate container see if the
class or method needs a dependencies it will make
AutoWiring
- AutoWiring :- means if the class or method have
dependencies type hinted , then it will use reflection to get
the type hinted instance .
- what is reflection :-
http://php.net/manual/en/book.reflection.php
Service Container
- Binding
app()->bind( Car::class , function() {
return new LamboCar();
}
);
- Resolving
app(Car::class) // means when someone asks for instance
from Car::class it will return new LamboCar instance .
Service Container
- Service Providers :-
This is the class where you bind services to the laravel app.
- php artisan make:provider TestProvider
- register() :- this is where you bind things into container
- boot() :- called after all register methods in other providers
have been called . //this is where you register events listeners
or routes and do any behaviour .
Service Container
- In config/app.php see the providers array .
- Now try to play around with this package :-
https://github.com/mcamara/laravel-localization
Thank You
- These slides are based on
Laravel Up & Running Book
http://shop.oreilly.com/product/0636920044116.do
Taylor Otwel Talk At Laracon Online March-2017
Matt Stuffer Talk At Laracon Online March-2017
Laravel Documentation
https://laravel.com/docs/master
Author
Ahmed Mohamed Abd El Ftah Intake 36 graduate
- Gmail :- ahmedabdelftah95165@gmail.com
- LinkedIn :- https://goo.gl/b5j8aS

More Related Content

PDF
Introdução APIs RESTful
PPTX
Introduction Ă  React
PPTX
Introduction Ă  Symfony
PDF
MVC in PHP
PPTX
Chp2 - Vers les Architectures Orientées Services
PDF
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
PPTX
Introduction Ă  Laravel
PPTX
Event handling
Introdução APIs RESTful
Introduction Ă  React
Introduction Ă  Symfony
MVC in PHP
Chp2 - Vers les Architectures Orientées Services
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
Introduction Ă  Laravel
Event handling

What's hot (20)

PDF
REST API and CRUD
PDF
Spring Framework - Data Access
PPTX
Spring Boot Tutorial
PPTX
Test automation of ap is using postman
PDF
Getting started with Spring Security
PDF
Rest api 테슀튞 수행가읎드
PDF
Android-Tp4: stockage
PDF
SOA - Architecture Orientée Service : Démystification
PDF
OAuth2 and Spring Security
PPTX
Introduction à spring boot
PPTX
Testing RESTful web services with REST Assured
PDF
Java Server Faces 2
PDF
2015-StarWest presentation on REST-assured
PDF
TestNG Annotations in Selenium | Edureka
PDF
Support de cours EJB 3 version complÚte Par Mr Youssfi, ENSET, Université Ha...
PDF
Kotlin의 ìœ”ëŁší‹Žì€ ì–Žë–»êȌ 동작하는가
PPTX
Soap vs rest
PDF
Collections In Java
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
PDF
What's new in selenium 4
REST API and CRUD
Spring Framework - Data Access
Spring Boot Tutorial
Test automation of ap is using postman
Getting started with Spring Security
Rest api 테슀튞 수행가읎드
Android-Tp4: stockage
SOA - Architecture Orientée Service : Démystification
OAuth2 and Spring Security
Introduction à spring boot
Testing RESTful web services with REST Assured
Java Server Faces 2
2015-StarWest presentation on REST-assured
TestNG Annotations in Selenium | Edureka
Support de cours EJB 3 version complÚte Par Mr Youssfi, ENSET, Université Ha...
Kotlin의 ìœ”ëŁší‹Žì€ ì–Žë–»êȌ 동작하는가
Soap vs rest
Collections In Java
Std 12 computer chapter 8 classes and object in java (part 2)
What's new in selenium 4
Ad

Similar to Laravel intake 37 all days (20)

PPTX
What-is-Laravel-23-August-2017.pptx
PPTX
What-is-Laravel and introduciton to Laravel
PPTX
Laravel
PPTX
Introduction to Laravel Framework (5.2)
PDF
Getting to know Laravel 5
PDF
Laravel Introduction
PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
ODP
Laravel 5.3 - Web Development Php framework
PDF
Laravel 101
PDF
SDPHP Lightning Talk - Let's Talk Laravel
PDF
Laravel 4 presentation
PPTX
Laravel ppt
PDF
What's New In Laravel 5
PDF
Introduction to Laravel
PPTX
Laravel 5
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
PDF
Why Laravel?
PPTX
Lecture 2_ Intro to laravel.pptx
DOCX
Laravel
PDF
Laravel presentation
What-is-Laravel-23-August-2017.pptx
What-is-Laravel and introduciton to Laravel
Laravel
Introduction to Laravel Framework (5.2)
Getting to know Laravel 5
Laravel Introduction
RESTful API development in Laravel 4 - Christopher Pecoraro
Laravel 5.3 - Web Development Php framework
Laravel 101
SDPHP Lightning Talk - Let's Talk Laravel
Laravel 4 presentation
Laravel ppt
What's New In Laravel 5
Introduction to Laravel
Laravel 5
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Why Laravel?
Lecture 2_ Intro to laravel.pptx
Laravel
Laravel presentation
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
top salesforce developer skills in 2025.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
AI in Product Development-omnex systems
PDF
medical staffing services at VALiNTRY
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Introduction to Artificial Intelligence
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
top salesforce developer skills in 2025.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Softaken Excel to vCard Converter Software.pdf
AI in Product Development-omnex systems
medical staffing services at VALiNTRY
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 2 - PM Management and IT Context
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
2025 Textile ERP Trends: SAP, Odoo & Oracle
Introduction to Artificial Intelligence
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers

Laravel intake 37 all days

  • 2. Content ● History ● Composer ● Install Laravel ● Directory Structure ● Routing ● Blade Templating Engine ● Database & Eloquent ● Request Validation & Middleware ● Service Container
  • 3. History - DHH released first version of ruby on rails on 2004 - Some of php frameworks got inspired by RoR - In 2010 taylor become dissatisfied with CodeIgniter as They were slow to catch up new features like namesapces
  • 4. History - Laravel 1 (June 2011) included built in support for (authentication - routing - models - views - ..) - Laravel 2 (September 2011) included support for (controllers - blade template engine - IOC - .. ) - Laravel 3 (February 2012) included support for (CLI Artisan - events - migrations - bundles - ..)
  • 5. History - Laravel 4 (May 2013 ) taylor rewrote framework from scratch and developed set of components under code name Illuminate , and pulled majority of components from symfony also included support for ( seeding - soft delete - ..) - Laravel 5 (Feb 2015) new directory tree structure and included support for (socialite - elixir - dotenv -...)
  • 6. Composer - Composer is a dependency manager like npm for node or ruby gems for ruby . - Download From here https://getcomposer.org/download/ - Make composer globally https://getcomposer.org/doc/00-intro.md#globally
  • 8. Directory Structure - Laravel Version 5.4 you will see :- - app/ --> where your application go like ( models controllers) - bootstrap/ --> files laravel uses to boot every time - config/ --> configuration files like (database configuration) - database/ --> where (migrations - seeds - factories) exist - public/ --> directory where server points to it when serving request it also contains (index.php) - resources/ --> contains (views - Saas -Less files - ..) - routes/ --> all routes definitions (Api - console -http)
  • 9. Directory Structure - storage/ --> where cache logs compiled files exist - tests/ --> where unit & integration test exist - vendor/ --> composer packages - .env --> defines environments variables - .env.example --> same as above ,it should be copied when cloning other projects - .gitattributes , .gitignore --> git configuration files - artisan --> php script to run artisan commands
  • 10. Directory Structure - composer.json , composer.lock --> contains project dependencies - package.json --> like composer.json for frontend assets - phpunit.xml --> configuration for php unit - readme.md --> markdown for laravel introduction - server.php --> it’s a server that emulate apache mod_rewrite - webpack.mix.js --> used for compiling and mixing frontend assets
  • 11. Routing - Controller’s Method Route::get(‘/posts’ , ‘PostsController@index’); - Parameters Route::get(‘/posts/{id}’ , ‘PostsController@edit’);
  • 12. Routing - Named Routes Route::get(‘/posts’ , [ ‘uses’ => ‘PostsController@index’, ‘as’ => ‘posts.index’ ]); more at https://laravel.com/docs/5.4/routing
  • 13. Blade - Blade is inspired by .NET’s Razor engine . - echo data :- {{ $post }} instead of <?php echo $post ; ?> - conditions :- @if ($post->name == ‘firstPost’) // do some stuff @endif
  • 14. Blade - looping :- @foreach($posts as $post) //do some stuff @endforeach - inheritance :- @exnteds(‘layouts.master’) - define sections :- @section(‘content’) <h1> hello from the content @endsection
  • 15. Blade - printing sections :- @yield(‘content’) - including :- @include(‘scripts’) - Including with parameters :- @include(‘post.form’,[‘method’ => ‘POST’]) more at https://laravel.com/docs/master/blade#introduction
  • 16. Database & Eloquent - Laravel ORM is called Eloquent - Database configuration in .env file or from config/database.php. - Laravel migration helps in making database persistent across multiple machines . - DB facade used to form query builder object
  • 17. Database & Eloquent - $post = DB::table(‘posts’)->find(20); //finds a row with id = 20 - $posts = DB::table('posts')->get(); //get all rows in posts table - $singlePost = DB::table(‘posts’)->where(‘name’ , ‘FirstPost’)->get(); //where conditions to query - $firstPost = DB::table(‘posts’)->first(); //gets the first row
  • 18. Database & Eloquent - DB::table(‘posts’)->insert( [‘title’ => ‘first post title’ , ‘desc’ => ‘first post desc ‘] ); //inserting a row - DB::table('posts')->where(‘id’ , 1)->delete(); //deletes a row - DB::table(‘posts’)->where(‘id’ , 1) ->update( [ ‘title’ => ‘changed title post ] ); //update the post title only
  • 19. Database & Eloquent - php artisan make:model Post //create a new model class - Laravel by default gets the plural name of model as a table name and makes query based on that - Post::all() //will search in posts table and get all rows - Post::create([‘title’ => ‘first post’ , ‘desc’ => ‘desc post’); //this will give a MassAssignmentException unless you override $fillable
  • 20. Database & Eloquent - Post::find(25)->update([‘title’ => ‘update post title’) //updates title for post with id 25 - Post::where(‘votes’, 23)->delete() //deletes any post have votes with 23
  • 21. Database & Eloquent - To define a relation in Post model you will define a function in the class for example i want to say post have many sections . //in Post model class public function sections () { return $this->hasMany(Section::class);} // in controller for example $postSections = Post::find(23)->sections;
  • 22. Database & Eloquent - Remember that query results are collection objects - More at Eloquent https://laravel.com/docs/master/eloquent#introduction - More at Collections https://laravel.com/docs/master/collections#available-meth ods
  • 23. Request Validation - Request Life Cycle :- See index.php first it loads the composers’s autload file . Then we bootstrap laravel application container and register some basic service providers like Log Service provider look at Illuminate/Foundation/Application.php constructor method . Finally we create instance of kernel to register providers and take user request and process it through middlewares & handle exception then return response
  • 24. Request Validation - In Controller :- $this->validate( $request , [ ‘title ‘ => ‘required ‘, ‘desc’ => ‘required|max:255’ ] , [ ‘title.required’ => ‘title is required to be filled ‘ , ‘desc.max’ => ‘description max num of chars is 255 ‘ ]);
  • 25. Request Validation - Another way with request file :- php artisan make:request PostsStoreRequest Then in authorize method make it return true . After that define your rules in rules method . - validation rules :- https://laravel.com/docs/master/validation#available-validation-rules - custom validation messages in request file :- https://laravel.com/docs/master/validation#customizing-the-error-messages
  • 26. Middleware - It’s a series of layers around the application , every request passes through middlewares . - Middlewares can inspect the request to decorate or reject it - Also middlewares can decorate the response . - register the middlewares in app/Http/Kernel.php - handle($request , ..) method where you handle the request and choose to pass it for the next middleware or not .
  • 28. Service Container - Other names for service container ( IOC container , DI container , Application container ) - Dependency Injection (DI) :- Instead to make object instantiate it’s dependencies internally , it will be passed from outside .
  • 29. Service Container - Class User { function __construct () { $mysqlConnection = new Mysql(); } } $user = new User(); // in this way object instantiated it’s dependencies internally
  • 30. Service Container - Class User { protected $dbConnection; //DB is an interface to easily switch between different db drivers function __construct (DB $db) { $this->dbConnection = $db; } } $mysqlConnection = new Mysql(); $user = new User( $mysqlConnection ); // the user object dependencies are passed from outside .
  • 31. Service Container - Service container in laravel responsible for binding & resolving & AutoWiring - Try this in controller :- public function index (Request $request) { dd($request); } // so how does the $request prints an object without instantiating it !!?
  • 32. Service Container - In the previous example , the illuminate container see if the class or method needs a dependencies it will make AutoWiring - AutoWiring :- means if the class or method have dependencies type hinted , then it will use reflection to get the type hinted instance . - what is reflection :- http://php.net/manual/en/book.reflection.php
  • 33. Service Container - Binding app()->bind( Car::class , function() { return new LamboCar(); } ); - Resolving app(Car::class) // means when someone asks for instance from Car::class it will return new LamboCar instance .
  • 34. Service Container - Service Providers :- This is the class where you bind services to the laravel app. - php artisan make:provider TestProvider - register() :- this is where you bind things into container - boot() :- called after all register methods in other providers have been called . //this is where you register events listeners or routes and do any behaviour .
  • 35. Service Container - In config/app.php see the providers array . - Now try to play around with this package :- https://github.com/mcamara/laravel-localization
  • 36. Thank You - These slides are based on Laravel Up & Running Book http://shop.oreilly.com/product/0636920044116.do Taylor Otwel Talk At Laracon Online March-2017 Matt Stuffer Talk At Laracon Online March-2017 Laravel Documentation https://laravel.com/docs/master
  • 37. Author Ahmed Mohamed Abd El Ftah Intake 36 graduate - Gmail :- ahmedabdelftah95165@gmail.com - LinkedIn :- https://goo.gl/b5j8aS