0%

Book Description

Develop robust modern web-based software applications and RESTful APIs with Laravel, one of the hottest PHP frameworks

In Detail

PHP continues to revive and Laravel is at its forefront. Laravel follows modern PHP's object-oriented best practices and reduces time-to-market, enabling you to build robust web and API-driven mobile applications that can be automatically tested and deployed.

With this book you will learn how to rapidly develop software applications using the Laravel 5 PHP framework.

This book walks you through the creation of an application, starting with behavior-driven design of entities. You'll explore various aspects of modern software including the RESTful API, and will be introduced to command bus. Laravel's annotations package is also explained and demonstrated. Finally, the book closes with a demonstration of different ways to deploy and scale your applications.

What You Will Learn

  • Convert specifications into classes and functions, using a specification-based behavioral-driven design (BDD)
  • Create a deployment script for a continuous delivery environment
  • Use Eloquent to interact with the database in an object-oriented manner
  • Easily scale software with route caching and the read/write configuration
  • Use DocBlock annotations to enhance controllers and reduce the amount of code required

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Mastering Laravel
    1. Table of Contents
    2. Mastering Laravel
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Designing Done Right with phpspec
      1. A new era
        1. A leaner app
        2. PSR
      2. Installing and configuring Laravel
        1. Installation
        2. Configuration
        3. Namespacing
      3. TDD done right
        1. PHPUnit
      4. phpspec
      5. Entity creation
      6. The MyCompany database schema
      7. Designing with phpspec
      8. Specifying with phpspec
        1. Red, green, refactor
        2. Tidying things up
      9. Controllers
        1. The command bus
      10. Summary
    9. 2. Automating Tests – Migrating and Seeding Your Database
      1. Using Laravel's migration feature
        1. An example of migration
        2. Creating the table
        3. The Laravel migration magic
        4. $table->timestamps();
      2. From schema to migration
        1. Composer's require-dev command
        2. Laravel's providers array
        3. The composer update command
        4. Generating the migrations
      3. Migration anatomy
        1. List tables
        2. The softDelete and timestamp properties
      4. Creating seeds
      5. Database testing with PHPUnit
        1. Running PHPUnit
      6. Functional testing with Behat
      7. Summary
    10. 3. Building Services, Commands, and Events
      1. Request routing
        1. User stories
        2. User stories to code
        3. The controller
          1. Searching for the room
          2. Controller to command
          3. Command to event
          4. The ReserveRoomCommandHandler class
          5. Event to handler
        4. Queued event handlers
        5. The waiting list command
        6. The queued commands
        7. The console command
        8. The command scheduler
      2. Summary
    11. 4. Creating RESTful APIs
      1. RESTful APIs in Laravel
      2. Essential CRUD
      3. Bonus features
      4. Controller creation
      5. CRUD(L) by example
        1. cRudl – read
        2. crudL – list
          1. Pagination
        3. Crudl – create
        4. crUdl – update
        5. cruDl – delete
      6. Model binding
        1. Read revisited
        2. List revisited
        3. Update revisited
        4. Delete revisited
      7. Moving beyond CRUD
      8. Nested controllers
        1. Accommodation hasMany rooms
        2. Room belongsTo accommodation
        3. Eloquent relations
        4. Nested update
        5. Nested create
      9. Eloquent model casting
      10. Route caching
      11. Summary
    12. 5. Using the Form Builder
      1. History
      2. Installing the HTML package
      3. Building web pages with Laravel
        1. The master template
        2. An example page
        3. From static HTML to static methods
          1. The form tag
          2. The text input field
          3. The label tag
          4. Checkbox
          5. The submit button
          6. The anchor tag with links
          7. Closing the form
          8. The resultant form
      4. Our example
        1. Month select
        2. Date select
        3. Year select
        4. Form macros
      5. Conclusion
      6. Summary
    13. 6. Taming Complexity with Annotations
      1. Annotations in other programming languages
        1. Annotations in Java
        2. Annotations in C#
        3. Annotations in PHP
      2. DocBlock annotations
        1. DocBlock annotations in Laravel
          1. Symfony
          2. Zend
          3. Laravel
      3. Resource controller using DocBlock annotations
      4. Single method routing
      5. Scanning routes
      6. Automatic scanning
      7. Additional annotations
        1. HTTP verbs
          1. Other annotations
      8. Using annotations in Laravel 5
        1. Advantages
      9. Conclusion
      10. Summary
    14. 7. Filtering Requests with Middleware
      1. The HTTP kernel
      2. The basic middleware structure
      3. Route middleware unravelled
        1. Default middleware – the Authenticate class
        2. Contracts
        3. Handle
        4. Custom middleware – Log
          1. The Log model
          2. Log model migration
        5. Terminable middleware
          1. Logging as terminable
      4. Using middleware
        1. Route groups
        2. Multiple middleware in route groups
      5. Middleware exclusion and inclusion
      6. Conclusion
      7. Summary
    15. 8. Querying the Database with the Eloquent ORM
      1. Basic operations
        1. Finding one
        2. The where method
        3. Chaining functions
        4. Finding all
      2. Eloquent relations
        1. One-to-one
        2. One-to-many
        3. Many-to-many
        4. Has-many-through
      3. Polymorphic relations
        1. Amenitiable relationships
          1. The Amenity table structure
          2. The Amenity model
          3. The Accommodation model
          4. The Room model
        2. Many-to-many polymorphic relations
        3. Has relationships
        4. Eager loading
      4. Conclusion
      5. Summary
    16. 9. Scaling Laravel
      1. Scalability issues
      2. Towards the enterprise
      3. Route caching
        1. Illuminate routing
        2. Lumen
        3. Comparison between Laravel and Lumen
        4. Lean application development
        5. Read/write
        6. Master table
        7. Slave table
        8. Configuring read/write
      4. Creating a master/slave database configuration
        1. Master server set up
        2. Slave server set up
      5. Summary
    17. 10. Building, Compiling, and Testing with Elixir
      1. Automating Laravel
        1. Deployment
        2. Development or deployment
      2. Towards automation
      3. From Gulp to Elixir
      4. Getting started
        1. Installing Node.js
        2. Installing the Node.js package manager
        3. Installing Gulp
        4. Installing Elixir
      5. Running Elixir
      6. Setting up notifications
      7. Combining CSS and JavaScript files with Elixir
      8. Compiling with Laravel Elixir
        1. Compiling Sass and Less
        2. Compiling CoffeeScript
        3. A summary of compiler commands
        4. Putting everything together
      9. Running tests with Elixir
        1. PHPSpec
        2. PHPUnit
        3. Creating custom tasks
      10. Setting up a file watcher
      11. Additional Laravel Elixir tasks
      12. Summary
    18. Index