You are previewing Laravel Application Development Cookbook.
O'Reilly logo
Laravel Application Development Cookbook

Book Description

Since Laravel is so versatile, one of the best learning routes is a cookbook. We’ve included lots of recipes and guidance on building web application, both simple and complex. It’s a pick & mix approach that works brilliantly.

  • Install and set up a Laravel application and then deploy and integrate third parties in your application

  • Create a secure authentication system and build a RESTful API

  • Build your own Composer Package and incorporate JavaScript and AJAX methods into Laravel

  • In Detail

    When creating a web application, there are many PHP frameworks from which to choose. Some are very easy to set up, and some have a much steeper learning curve. Laravel offers both paths. You can do a quick installation and have your app up-and-running in no time, or you can use Laravel’s extensibility to create an advanced and fully-featured app.

    Laravel Application Development Cookbook provides you with working code examples for many of the common problems that web developers face. In the process, it will also allow both new and existing Laravel users to expand their knowledge of the framework.

    This book will walk you through all aspects of Laravel development. It begins with basic set up and installation procedures, and continues through more advanced use cases.

    You will also learn about all the helpful features that Laravel provides to make your development quick and easy. For more advanced needs, you will also see how to utilize Laravel’s authentication features and how to create a RESTful API.

    In the Laravel Application Development Cookbook, you will learn everything you need to know about a great PHP framework, with working code that will get you up-and-running in no time.

    Table of Contents

    1. Laravel Application Development Cookbook
      1. Table of Contents
      2. Laravel Application Development Cookbook
      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. Setting Up and Installing Laravel
        1. Introduction
        2. Installing Laravel as a git submodule
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Setting up a virtual host and development environment in Apache
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Creating "clean" URLs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Configuring Laravel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Using Laravel with Sublime Text 2
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Setting up your IDE to autocomplete Laravel's namespaces
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Using Autoloader to map a class name to its file
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Creating advanced Autoloaders with namespaces and directories
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      9. 2. Using Forms and Gathering Input
        1. Introduction
        2. Creating a simple form
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Gathering form input to display on another page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Validating user input
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Creating a file uploader
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Validating a file upload
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Creating a custom error message
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Adding a honey pot to a form
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Uploading an image using Redactor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        10. Cropping an image with Jcrop
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        11. Creating an autocomplete text input
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        12. Making a CAPTCHA-style spam catcher
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Authenticating Your Application
        1. Introduction
        2. Setting up and configuring the Auth library
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating an authentication system
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Retrieving and updating user info after logging in
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Restricting access to certain pages
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Setting up OAuth with the HybridAuth package
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Using OpenID for logins
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Logging in using Facebook credentials
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Logging in using Twitter credentials
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        10. Logging in using LinkedIn
          1. Getting ready
          2. How to do it...
          3. How it works...
      11. 4. Storing and Using Data
        1. Introduction
        2. Creating data tables using migrations and schemas
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        3. Querying using raw SQL statements
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Querying using Fluent
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Querying using Eloquent ORM
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Using automatic validation in models
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Using advanced Eloquent and relationships
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Creating a CRUD system
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Importing a CSV using Eloquent
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Using RSS as a data source
          1. Getting ready
          2. How to do it...
          3. How it works...
        11. Using attributes to change table column names
          1. Getting ready
          2. How to do it...
          3. How it works...
        12. Using a non-Eloquent ORM in Laravel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      12. 5. Using Controllers and Routes for URLs and APIs
        1. Introduction
        2. Creating a basic controller
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating a route using a closure
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Creating a RESTful controller
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using advanced routing
          1. Getting ready
          2. How to do it…
          3. How it works...
        6. Using a filter on the route
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Using route groups
          1. Getting ready
          2. How to do it…
          3. How it works...
        8. Building a RESTful API with routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Using named routes
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Using a subdomain in your route
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      13. 6. Displaying Your Views
        1. Introduction
        2. Creating and using a basic view
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Passing data into a view
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
        4. Loading a view into another view/nested views
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Adding assets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Creating a view using Blade
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Using TWIG templates
          1. Getting ready
          2. How to do it…
          3. How it works...
        8. Utilizing advanced Blade usage
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Creating localization of content
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Creating menus in Laravel
          1. Getting ready
          2. How to do it...
          3. How it works...
        11. Integrating with Bootstrap
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        12. Using named views and view composers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      14. 7. Creating and Using Composer Packages
        1. Introduction
        2. Downloading and installing packages
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using the Generators package to set up an app
          1. Getting ready
          2. How to do it…
          3. How it works...
        4. Creating a Composer package in Laravel
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
        5. Adding your Composer package to Packagist
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Adding a non-Packagist package to Composer
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Creating a custom artisan command
          1. Getting ready
          2. How to do it...
          3. How it works...
      15. 8. Using Ajax and jQuery
        1. Introduction
        2. Getting data from another page
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Setting up a controller to return JSON data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Creating an Ajax search function
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Creating and validating a user using Ajax
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Filtering data based on checkbox selection
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Making an Ajax newsletter sign-up box
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
          5. See also
        8. Sending an e-mail using Laravel and jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Creating a sortable table using jQuery and Laravel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      16. 9. Using Security and Sessions Effectively
        1. Introduction
        2. Encrypting and decrypting data
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Hashing passwords and other data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Using CSRF tokens and filters in forms
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Using advanced validation in forms
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Building a shopping cart
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Using Redis to save sessions
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using basic sessions and cookies
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
        9. Creating a secure API server
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      17. 10. Testing and Debugging Your App
        1. Introduction
        2. Setting up and configuring PHPUnit
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Writing and running a test case
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Using Mockery to test controllers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Writing acceptance tests using Codeception
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Debugging and profiling your app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      18. 11. Deploying and Integrating Third-party Services into Your Application
        1. Introduction
        2. Creating a queue and using Artisan to run it
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Deploying a Laravel app to Pagoda Box
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Using the Stripe payment gateway with Laravel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Doing a GeoIP lookup and setting custom routing
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Gathering e-mail addresses and using them with a third-party e-mail service
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Storing and retrieving cloud content from Amazon S3
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
          5. See also
      19. Index