Laravel 5 Essentials

Book description

Explore the fundamentals of Laravel, one of the most expressive and robust PHP frameworks available

In Detail

Laravel has established itself as one of the most popular PHP frameworks over the past couple of years. Its popularity comes due to its ease of use, expressive syntax, and the number of components it has, allowing you to achieve practically any task in a modern PHP application.

If you've not had the opportunity to dive into Laravel yet, then this book will be the perfect companion, as it covers the fundamentals Laravel is built on in a thorough yet easy-to-follow manner. To make this book your best learning source, we have covered integral topics such as preparing an environment for working with Laravel applications, creating your first Laravel application from start to finish, a tour of Laravel's ORM Eloquent, and more advanced topics such as testing, user authentication, and security. Being one of the most interesting features in Laravel, we also cover an overview of Artisan, including descriptions of some of its tasks. Post this, we talk about testing and security. By the end of this book, you will be able to create robust PHP websites and web applications quickly and efficiently.

What You Will Learn

  • Set up a development environment for working with Laravel apps

  • Create a working Laravel application from start to finish

  • Interact with data and discover Eloquent, Laravel's own ORM

  • Create and run migrations and seeds

  • Simplify command-line tasks by building Artisan commands

  • Protect your app by securing it from common security vulnerabilities

  • Perform end-to-end testing after learning the basics of testing in Laravel

  • Learn about Laravel's other features including service providers, packages, queue workers, and helpers for working with strings and arrays

  • Table of contents

    1. Laravel 5 Essentials
      1. Table of Contents
      2. Laravel 5 Essentials
      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. An Introduction to Laravel
        1. The need for frameworks
          1. The limitations of homemade tools
          2. Laravel to the rescue
        2. A new approach to developing PHP applications
          1. A more robust HTTP foundation
          2. Embracing PHP
        3. Laravel's main features and sources of inspiration
          1. Expressiveness and simplicity
            1. Prettifying PHP
          2. Responsibilities, naming, and conventions
          3. Helping you become a better developer
        4. Structure of a Laravel application
          1. The service container and request lifecycle
          2. Exploring Laravel
          3. Changes in Version 5 from Version 4
        5. Summary
      9. 2. Setting Up a Development Environment
        1. Meeting Composer
        2. Working with the command line
        3. Meet Homestead
          1. Installing Homestead
          2. Everyday usage of Homestead
            1. Adding additional websites
            2. Connecting to your databases
        4. Creating a new Laravel application
        5. Summary
      10. 3. Your First Application
        1. Planning our application
          1. Entities, relationships, and attributes
          2. The map of our application
        2. Starting the application
          1. Setting the application namespace
        3. Writing the first routes
          1. Restricting the route parameters
          2. Handling HTTP exceptions
          3. Performing redirections
          4. Returning views
        4. Preparing the database
          1. Creating Eloquent models
          2. Building the database schema
          3. Seeding the database
        5. Mastering Blade
          1. Creating a master view
        6. Back to the routes
          1. The overview page
          2. Displaying a cat's page
            1. Route-model binding
          3. Adding, editing, and deleting cats
        7. Moving from simple routing to powerful controllers
          1. Resource controllers
        8. Summary
      11. 4. Eloquent ORM
        1. Eloquent conventions
        2. Retrieving data
          1. Filtering records
        3. Saving data
          1. Mass assignment
        4. Deleting data
          1. Soft deletion
            1. Including deleted models in results
        5. Query scopes
        6. Relationships
          1. One-to-one
          2. Many-to-many
            1. Storing data in the pivot table
          3. Has-many-through
          4. Polymorphic relations
          5. Many-to-many polymorphic relations
        7. Model events
          1. Registering event listeners
          2. Model observers
        8. Collections
          1. Checking whether a key exists in a collection
        9. Summary
      12. 5. Testing – It's Easier Than You Think
        1. The benefits of testing
        2. The anatomy of a test
        3. Unit testing with PHPUnit
          1. Defining what you expect with assertions
          2. Preparing the scene and cleaning up objects
          3. Expecting exceptions
          4. Testing interdependent classes in isolation
        4. End-to-end testing
          1. Testing – batteries included
          2. Framework assertions
          3. Impersonating users
          4. Testing with a database
          5. Inspecting the rendered views
        5. Summary
      13. 6. A Command-line Companion Called Artisan
        1. Keeping up with the latest changes
        2. Inspecting and interacting with your application
          1. Fiddling with the internals
          2. Turning the engine off
          3. Fine-tuning your application
          4. Caching routes
          5. Generators
        3. Rolling out your own Artisan commands
          1. Creating the command
          2. The anatomy of a command
          3. Writing the command
        4. Scheduling commands
          1. Viewing the output of scheduled commands
        5. Summary
      14. 7. Authentication and Security
        1. Authenticating users
          1. Creating the user model
          2. Creating the necessary database schema
          3. Authentication routes and views
          4. Middleware
          5. Validating user input
            1. Form requests
        2. Securing your application
          1. Cross-site request forgery
          2. Escaping content to prevent cross-site scripting (XSS)
          3. Avoiding SQL injection
          4. Using mass assignment with care
          5. Cookies – secure by default
          6. Forcing HTTPS when exchanging sensitive data
        3. Summary
      15. A. An Arsenal of Tools
        1. Array helpers
          1. The usage examples of array helpers
        2. String and text manipulation
          1. Boolean functions
          2. Transformation functions
          3. Inflection functions
        3. Dealing with files
          1. File uploads
        4. Sending e-mails
        5. Easier date and time handling with Carbon
          1. Instantiating Carbon objects
          2. Outputting user-friendly timestamps
          3. Boolean methods
          4. Carbon for Eloquent DateTime properties
        6. Don't wait any longer with queues
          1. Creating a command and pushing it onto the queue
          2. Listening to a queue and executing jobs
          3. Getting notified when a job fails
          4. Queues without background processes
        7. Where to go next?
      16. Index

    Product information

    • Title: Laravel 5 Essentials
    • Author(s): Martin Bean
    • Release date: April 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781785283017