Getting Started with Laravel 4

Getting Started with Laravel 4
eBook: $20.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $55.98    Print cover: $34.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Provides a concise introduction to all the concepts needed to get started with Laravel
  • Walks through the different steps involved in creating a complete Laravel application
  • Gives an overview of Laravel's advanced features that can be used when applications grow in complexity
  • Learn how to build structured, more maintainable, and more secure applications with less code by using Laravel

Book Details

Language : English
Paperback : 128 pages [ 235mm x 191mm ]
Release Date : January 2014
ISBN : 1783287039
ISBN 13 : 9781783287031
Author(s) : Raphaël Saunier
Topics and Technologies : All Books, Web Development, Open Source

Table of Contents

Chapter 1: Meeting Laravel
Chapter 2: Composer All Over
Chapter 3: Your First Application
Chapter 4: Authentication and Security
Chapter 5: Testing – It's Easier Than You Think
Chapter 6: A Command-line Companion Called Artisan
Chapter 7: Architecting Ambitious Applications
Appendix: An Arsenal of Tools
  • Chapter 1: Meeting Laravel
    • The need for frameworks
      • The limitations of homemade tools
      • Laravel to the rescue
    • A new approach to developing PHP applications
      • A more robust HTTP foundation
      • Embracing PHP
    • Laravel's main features and sources of inspiration
      • Expressiveness and simplicity
        • Prettifying PHP
      • Responsibilities, naming, and conventions
      • Helping you become a better developer
    • Structure of a Laravel application
      • The application container and request lifecycle
      • Exploring Laravel
      • Moving from Version 3 to Version 4
    • Summary
    • Chapter 2: Composer All Over
      • Working with the command line
      • How does Composer work?
      • Installation
        • Unix (Mac OS, Linux)
        • Windows
      • Creating a new Laravel application
      • Finding and installing new packages
      • Additional advice
      • Summary
      • Chapter 3: Your First Application
        • Sketching out the application
          • Entities, relationships, and attributes
          • The map of our application
        • Starting the application
          • Using the built-in development server
        • Writing the first routes
          • Restricting the route parameters
          • Catching the missing routes
          • Handling redirections
          • Returning views
        • Preparing the database
          • Creating the Eloquent models
          • Building the database schema
          • Seeding the database
        • Mastering Blade
          • Creating a master view
        • Back to the routes
          • The overview page
          • Displaying a cat's page
          • Adding, editing, and deleting cats
        • Summary
        • Chapter 4: Authentication and Security
          • Authenticating users
            • Creating the user model
            • Creating the necessary database schema
            • Authentication routes and views
            • Validating user input
          • Securing your application
            • Cross-site request forgery
            • Escaping content to prevent cross-site scripting – XSS
            • Avoiding SQL injection
            • Using mass-assignment with care
            • Cookies – secure by default
            • Forcing HTTPS when exchanging sensitive data
          • Summary
          • Chapter 5: Testing – It's Easier Than You Think
            • The benefits of testing
            • The anatomy of a test
            • Unit testing with PHPUnit
              • Defining what you expect with assertions
              • Preparing the scene and cleaning up objects
              • Expecting exceptions
              • Testing interdependent classes in isolation
            • End-to-end testing
              • Testing – batteries included
              • Framework assertions
              • Impersonating users
              • Testing with a database
              • Inspecting the rendered views
            • Summary
            • Chapter 6: A Command-line Companion Called Artisan
              • Keeping up with the latest changes
              • Inspecting and interacting with your application
                • Fiddling with the internals
                • Turning the engine off
                • Fine-tuning your application
              • Installing third-party commands
                • Speeding up your workflow with generators
                  • Generating migrations
                  • Generating HTML forms
                  • Generating everything else
                • Deploying with a single command
                  • Deployment, the old-school way
              • Rolling out your own artisan commands
                • Creating the command
                • The anatomy of a command
                • Writing the command
              • Summary
              • Chapter 7: Architecting Ambitious Applications
                • Moving from simple routing to powerful controllers
                  • Favoring explicit routing
                  • Straightforward REST routing
                • Supercharging your models
                  • Simple performance tricks
                    • Eager loading records
                    • Selecting only what you need
                    • Profiling your queries
                  • Foolproof models with soft deletes
                  • More control with SQL
                  • Listening for model events
                  • The handy paginator class
                • Environment configuration made easy
                  • Environments and Artisan
                  • Adding your own configuration settings
                • Bringing in your own classes
                • Playing nice with the frontend
                • Summary
                • Appendix: An Arsenal of Tools
                  • Array helpers
                    • The usage examples of array helpers
                  • String and text manipulation
                    • Boolean functions
                    • Transformation functions
                    • Inflection functions
                  • Dealing with files
                    • File uploads
                    • File manipulation methods
                  • Sending e-mails
                  • Easier date and time handling with Carbon
                    • Instantiating Carbon objects
                    • Outputting user-friendly timestamps
                    • Boolean methods
                    • Carbon for Eloquent DateTime properties
                  • Don't wait any longer with queues
                    • Creating a job and pushing it onto the queue
                    • Listening to a queue and executing jobs
                    • Getting notified when a job fails
                    • Queues without background processes
                  • Where to go next?

                  Raphaël Saunier

                  Raphaël Saunier works as a full-stack Web Developer for Information Architects in Zürich, Switzerland. He holds a degree in Information Management for Business from University College London.

                  He is always looking for excuses to learn and play with new technologies, tools, and techniques. He is also able to make pragmatic decisions that take into account the strengths and weaknesses of the many well-established tools at the disposal of web developers.

                  A strong advocate of Laravel, Ember.js, Vim, and PostgreSQL when he is among developers, he is also passionate about teaching programming and general computer literacy to people of all ages.

                  Code Downloads

                  Download the code and support files for this book.

                  Submit Errata

                  Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                  - 5 submitted: last submission 02 Jun 2014

                  Type: Code | Page: 109

                  class UsersTableSeeder extends Seeder {
                  public function run(){
                  array('username' =>'admin', 'password' => Hash::make('hunter2'),
                  'is_admin' => true));

                  'username' =>'scott', 'password' => Hash::make('tiger'),'is_admin' =>

                  This should be


                  class UsersTableSeeder extends Seeder { 
                      public function run(){ 

                              'username' =>'admin', 
                              'password' => Hash::make('hunter2'), 

                              'is_admin' => true

                              'username' =>'scott',
                              'password' => Hash::make('tiger'),

                              'is_admin' => false


                  Type: Graphics | Page: 41

                  There is a correction in the image on this page.

                  "@section('section')" should be "@section('content')"

                  Please refer to for more details.

                  Page: 51 | Type: Technical

                  The user model needs to have a new field added, "remember_token" that is a string. Without this field, the logout method will not work. 

                  This is correct. In 4.1.26 there was a change documented here:

                  In short, you have to add a (usually) VARCHAR(100) or TEXT field named remember_token to the users table. After this everything described in the book will work on the latest version of Laravel.

                  Page: 51Type: Code


                  Should be:


                  Page: 46 | Type: Code

                  <a href="{{('cats/'.$cat->id.'')}}">&larr; Cancel </a>

                  should be

                  <a href="{{url('cats/'.$cat->id)}}">&larr; Cancel </a>

                  Sample chapters

                  You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                  Frequently bought together

                  Getting Started with Laravel 4 +    Mastering Object-oriented Python =
                  50% Off
                  the second eBook
                  Price for both: £21.45

                  Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                  What you will learn from this book

                  • Install Laravel and other PHP packages with Composer
                  • Sketch out and structure your application with routes and controllers
                  • Create hierarchical templates with Blade
                  • Define models and how to issue database queries in PHP with Eloquent
                  • Authenticate users securely with minimal effort
                  • Avoid security issues and write bulletproof code
                  • Develop with confidence with the help of tests
                  • Set up and create powerful command line utilities

                  In Detail

                  PHP powers many of the largest websites on the planet. Yet, even though it was specifically created for the Web, its shortcomings never cease to frustrate developers. This is where a tool like Laravel comes in. Rather than reinventing the wheel, Laravel reuses tried and tested components and principles and bundles them to form a cohesive whole and makes PHP development enjoyable again.

                  Getting Started with Laravel 4 is a practical and concise introduction to the Laravel PHP framework. It covers its fundamental concepts and presents the many features that will boost your productivity when developing web applications. After introducing the key concepts and installing Composer, you will build a CRUD application and add more features to it in each successive chapter.

                  This book introduces you to a different and more enjoyable way of writing PHP applications. You will start by learning about the key principles and the same development practices that Laravel encourages. Then, in subsequent chapters, you will create and successively add more features to a web application.

                  You will learn how to use the arsenal of tools at your disposal and probably pick up some useful techniques along the way. Indeed, everything you will learn in this book is highly transferrable and applicable to other MVC frameworks. Laravel's routing mechanism, templating language, and object-relational mapper will have no more secrets for you. You will learn how to authenticate users, write tests, and create command line utilities that interact with your application with disconcerting ease. In addition to this, you will probably be surprised by the simplicity and expressiveness of your code.


                  This book follows a practical and easy-to-follow approach and is packed with real-world examples to understand all the fundamentals and concepts in a very concise way.

                  Who this book is for

                  This book is ideal for web developers who want to get up to speed with Laravel quickly. You are expected to have some experience with the PHP programming language – or any C-like languages such as JavaScript, Perl, or Java – along with some understanding of basic OOP concepts. Any experience with MVC frameworks such as ASP.NET MVC or Ruby on Rails will certainly be beneficial but not required. Lastly, some familiarity with command line interfaces will also help but is not essential either.

                  Code Download and Errata
                  Packt Anytime, Anywhere
                  Register Books
                  Print Upgrades
                  eBook Downloads
                  Video Support
                  Contact Us
                  Awards Voting Nominations Previous Winners
                  Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                  Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software