SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Edureka!
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksPhill Sparks
 
Création de Vues | SQL Oracle
Création de Vues | SQL OracleCréation de Vues | SQL Oracle
Création de Vues | SQL Oraclewebreaker
 
Introduction à React JS
Introduction à React JSIntroduction à React JS
Introduction à React JSAbdoulaye Dieng
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes WorkshopNir Kaufman
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Christian Schneider
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Eyal Vardi
 
Alphorm.com Java 8: les nouveautés
Alphorm.com Java 8: les nouveautésAlphorm.com Java 8: les nouveautés
Alphorm.com Java 8: les nouveautésAlphorm
 

Was ist angesagt? (20)

Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 
Création de Vues | SQL Oracle
Création de Vues | SQL OracleCréation de Vues | SQL Oracle
Création de Vues | SQL Oracle
 
Introduction à React JS
Introduction à React JSIntroduction à React JS
Introduction à React JS
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
Angular Lifecycle Hooks
Angular Lifecycle HooksAngular Lifecycle Hooks
Angular Lifecycle Hooks
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Spring security
Spring securitySpring security
Spring security
 
Laravel
LaravelLaravel
Laravel
 
Modele mvc
Modele mvcModele mvc
Modele mvc
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Ansible
AnsibleAnsible
Ansible
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Cours JavaScript
Cours JavaScriptCours JavaScript
Cours JavaScript
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Alphorm.com Java 8: les nouveautés
Alphorm.com Java 8: les nouveautésAlphorm.com Java 8: les nouveautés
Alphorm.com Java 8: les nouveautés
 

Ähnlich wie Laravel intake 37 all days

Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Henry S
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features APIcgmonroe
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectJonathan Wage
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02arghya007
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...King Foo
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 

Ähnlich wie Laravel intake 37 all days (20)

Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features API
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Laravel
LaravelLaravel
Laravel
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 

Kürzlich hochgeladen

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Kürzlich hochgeladen (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Laravel intake 37 all days

  • 1.
  • 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