Slide 1

Slide 1 text

26 November 2016 Illuminating Web Development With Laravel (5.x) Manan Jadhav https://curos.in

Slide 2

Slide 2 text

26 November 2016 Code Samples for this presentation https://github.com/CurosMJ/illuminating-web-development-with-laravel

Slide 3

Slide 3 text

26 November 2016 About Me Full Stack Web Developer (Android, Web and Server) I handle everything technical @ MotionDen & Utonexus. Co-Organizer, GDGBaroda. Third Year IT Engineering Student @ SVIT Vasad. https://curos.in

Slide 4

Slide 4 text

26 November 2016 Why ? ● UX and DX : Developer Experience ● Rapid Development ● Modern and Adapting : Composer, Design Patterns, Modern Workflows ● Standards : PHP-FIG and PSRs ● Ecosystem

Slide 5

Slide 5 text

26 November 2016 Composer ● Dependency Manager for PHP (npm, bower, pip) ● Autoloading. ● Using 3rd party PHP packages becomes a breeze. ● Effectively uses PHP Namespaces to organize code. ● https://getcomposer.org/

Slide 6

Slide 6 text

26 November 2016 PHP-FIG ● United Nations for the PHP world ● Leading frameworks have a representatives, and together they define standards for the PHP world, called PSRs : PHP Standards Recommendations ● http://www.php-fig.org/

Slide 7

Slide 7 text

26 November 2016 Ecosystem ● > 8800 Pull Requests & > 7400 Issues ● > 15000 Commits by > 1100 Contributors (Of which, I stand at #50) ● Most starred PHP Library on GitHub ● 5 Major Releases

Slide 8

Slide 8 text

26 November 2016 Let’s Start ● MVC Framework : Model-View-Controller ● Models : Eloquent ● Views: Blade Templating ● Controller: Framework Router

Slide 9

Slide 9 text

26 November 2016 Services ● Routing ● Templating ● Database ● Migrations ● Eloquent ORM ● Validation ● Session ● Authentication and more... IoC Container Facades Helper functions Dependency Injection

Slide 10

Slide 10 text

26 November 2016 Installation composer create-project laravel/laravel myapp --prefer-dist OR git clone https://github.com/laravel/laravel myapp cd myapp composer install --prefer-dist

Slide 11

Slide 11 text

26 November 2016 Application Structure Review

Slide 12

Slide 12 text

26 November 2016 Routing ● GET, POST, PUT, DELETE Routes ● Routing to Controllers ● Route Parameters ● Groups ● Middleware

Slide 13

Slide 13 text

26 November 2016 Templating ● Blade is the default template engine ● Blade is compiled ● Control Structures ● Passing data to Views ● Syntax == HTML with Blade and/or plain PHP

Slide 14

Slide 14 text

26 November 2016 Database ● Officially Supports MySQL, SQLite, Postgres and SQL Server ● SQL Query Builder ● Uses PDO - PHP Data Objects ● SQLi - safe : 1st Order & 2nd Order ● Transactions, Joins, Ordering, Grouping, “Safe” Inserts and updates, Raw SQL

Slide 15

Slide 15 text

26 November 2016 Migrations ● Painless team coordination over DB Schema ● Define database in code ● Keep record of all past schemas ● Modifying schemas becomes easy ● Bi-directional : Up and Down

Slide 16

Slide 16 text

26 November 2016 Eloquent ORM ● ActiveRecord ORM : Object Relational Mapping ● Interact with Database Entities as if they’re Objects ● Sensible Defaults : created_at, updated_at, table names, etc. ● Frequently used : find, findOrFail etc ● Returns “Collections” : feature rich array wrapper

Slide 17

Slide 17 text

26 November 2016 Validation ● Rule based parameter checking ● Exhaustive choice of rules ● Customizable error messages

Slide 18

Slide 18 text

26 November 2016 Session ● Multiple drivers : file, cookie, database, cache-based (redis) ● Simple key value store and simple API : ○ Session::get() Session::put() Session::flush() ● “Safe” : Data is stored server side only, and if cookie driver is used, it is kept encrypted

Slide 19

Slide 19 text

26 November 2016 Authentication ● Basic, Stateless, Stateful, OAuth Support. ● Ready to work, out of the box. ● Bootstrap code available. ● Simple API : ○ Auth::attempt(), Auth::check(), Auth::user(), Auth::logout()

Slide 20

Slide 20 text

26 November 2016 Design Patterns : Facades ● Auth::check(); Route::get(); ● In simple terms, Facade == Mask ● Facades have been around since Laravel 3 ● Provider a beautiful and simple way to interact with services

Slide 21

Slide 21 text

26 November 2016 Design Patterns : Dependency Injection & IoC ● Services == Objects == Instances of a Class ● IoC == Dependency Injection == Framework provides the service to us class MyController { private $db; public function __construct(Database $db) { $this->db = $db; } public function something() { //use $this->db instead of ‘DB::’} }

Slide 22

Slide 22 text

26 November 2016 Design Pattern : Inversion of Control ● You, the user are not responsible for managing dependencies. ● The framework provides you with whatever you need. ● You need to first teach recipes to the framework. Then you can ask for whatever you want.

Slide 23

Slide 23 text

26 November 2016 Laravel IoC Container // somewhere in code App::bind(‘Cheese’, function () { return new Cheese(); }); App::bind(‘Pizza’, function (Cheese $c) { return new Pizza($c); }); // later $pizza = App::make(‘Pizza’); // instead of $pizza = new Pizza(new Cheese());

Slide 24

Slide 24 text

26 November 2016 Laravel IoC Container ● ServiceProviders : responsible for binding services into container ● Each service has its own service provider ● You can create your own services using ServiceProviders or, just add new services in the AppServiceProvider.

Slide 25

Slide 25 text

26 November 2016 Design Patterns : Why DI & IoC? ● Saves you from dependency hell. ● SOLID : Single Responsibility Principle : Keep code simple ● SOLID : Liskov Substitution Principle : Use contracts ● SOLID : Interface Segregation Principle : Interfaces are better than concretes ● Makes is easy to change drivers, or underlying implementations.

Slide 26

Slide 26 text

26 November 2016 Request Lifecycle ● public/index.php (for web) OR artisan (for console) ● Laravel IoC Container created ● HttpKernel or ConsoleKernel is retrieved ● Both kernels run the service providers, services are created ● Request object is created and passed on to the Kernel ● Kernel dispatches to Router. Router routes, and returns.

Slide 27

Slide 27 text

26 November 2016 Laravel and Lumen ● Lumen = Laravel - Developer Experience + Performance ● Uses the same components as Laravel ● Facades are not available by default ● Authentication Bootstrapping code not available

Slide 28

Slide 28 text

26 November 2016 Further Learning https://laravel.com : Official Documentation https://laracasts.com : Really good video tutorials, but paid. https://mattstauffer.co/ : One of the best blogs on Laravel For help, https://larachat.co/ is the slack channel, you’ll find a lot of people availabe for help. Laravel Cashier, Socialite, Passport, Scout.

Slide 29

Slide 29 text

26 November 2016 Why “Illuminate”? “Illuminate” is the namespace root used by all of the core framework code. Illuminate was the codename for Laravel 4.2. Laravel is Illuminating the world of web development.

Slide 30

Slide 30 text

26 November 2016 Questions !?

Slide 31

Slide 31 text

26 November 2016 This Presentation : https://goo.gl/rLfGLL

Slide 32

Slide 32 text

26 November 2016 Code Samples for this presentation https://github.com/CurosMJ/illuminating-web-development-with-laravel