Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Illuminating Web Development With Laravel (5.x)

Manan Jadhav
November 26, 2016

Illuminating Web Development With Laravel (5.x)

Manan Jadhav

November 26, 2016
Tweet

More Decks by Manan Jadhav

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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/
  4. 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/
  5. 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
  6. 26 November 2016 Let’s Start • MVC Framework : Model-View-Controller

    • Models : Eloquent • Views: Blade Templating • Controller: Framework Router
  7. 26 November 2016 Services • Routing • Templating • Database

    • Migrations • Eloquent ORM • Validation • Session • Authentication and more... IoC Container Facades Helper functions Dependency Injection
  8. 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
  9. 26 November 2016 Routing • GET, POST, PUT, DELETE Routes

    • Routing to Controllers • Route Parameters • Groups • Middleware
  10. 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
  11. 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
  12. 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
  13. 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
  14. 26 November 2016 Validation • Rule based parameter checking •

    Exhaustive choice of rules • Customizable error messages
  15. 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
  16. 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()
  17. 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
  18. 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::’} }
  19. 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.
  20. 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());
  21. 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.
  22. 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.
  23. 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.
  24. 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
  25. 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.
  26. 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.