Book Image

Laravel 5 Essentials

By : Martin Bean
Book Image

Laravel 5 Essentials

By: Martin Bean

Overview of this book

Table of Contents (15 chapters)
Laravel 5 Essentials
About the Author
About the Reviewers


Application frameworks have grown in popularity over the past five years. There has been a tremendous shift from handwriting all code to leveraging these powerful frameworks with prebuilt components and features. However, with anything that comes to be in fashion, there are now a lot of contending options, and each of them viable.

While CodeIgniter was one of the first frameworks to enjoy widespread popularity, this popularity would come to be its undoing years later, as its large spread use and low barrier to entry meant it couldn't take advantage of newer versions of PHP without losing backwards compatibility, and potentially breaking lots of applications. This saw it then be surpassed by faster-moving alternatives such as Symfony and even FuelPHP, which was developed as a response to CodeIgniter's unwillingness to embrace change.

Enter: Laravel. Laravel joined the framework scene when there were already many players. However, the developers of Laravel used this timing to their advantage, instead creating a framework that avoided all of the problems and mistakes previous full stack frameworks had made and building on top of the excellent Symfony components in order to create a robust, component-based framework.

Instead of providing dozens of inflexible libraries, Laravel provides sensible, driver-based components that developers could use to build applications their own way, rather than trying to mash everything into the layout the framework author defined. This led to Laravel rising in popularity. It was also a fast-moving framework, and, by version 4, had become the most starred framework on GitHub, a testament to its popularity.

This book will give you a tour of Laravel and its core features. We'll look at how to manage multiple Laravel applications on the same machine and then we'll go ahead and start building our own Laravel application from scratch through to completion. Once we've got a basic application reading and writing data from a database, we'll take a look at Eloquent, Laravel's ORM, which is what makes it easy to read and write from a database and the more advanced features it offers. From there, we'll look at Artisan, Laravel's command-line utility, and even how to define our own commands. We'll then learn how to write automated tests for our application to make sure it keeps working the way we want it to, even with future developments. Then, finally, we'll look at how to build login and registration systems using Laravel's user authentication component.

By the end of the book, you'll have a complete Laravel application, as well as the tools and knowledge of how to build your own Laravel-based applications unassisted, and where to continue your learning of the framework.

What this book covers

Chapter 1, An Introduction to Laravel, takes a look at application frameworks in PHP in general, a recent history of the Laravel framework, and the principles that the Laravel framework is built upon.

Chapter 2, Setting Up a Development Environment, lays the foundation for what's needed to build Laravel applications by installing and configuring the Homestead virtual machine and the Composer dependency manager.

Chapter 3, Your First Application, builds a working application in Laravel from start to finish. Here is where the fun begins!

Chapter 4, Eloquent ORM, takes a look at Eloquent, the object relation mapper that ships with Laravel and allows you to query your databases easily.

Chapter 5, Testing – It's Easier Than You Think, goes over the various approaches to test your Laravel applications to make sure they're as solid as possible and still work as intended after adding new features.

Chapter 6, A Command-line Companion Called Artisan, helps us meet Artisan, the command-line utility for Laravel. We cover the commands Artisan offers out of the box, as well as how to create our own command-line tools.

Chapter 7, Authentication and Security, shows you the various ways to protect your Laravel applications from common attacks, as well as how to authenticate and authorize users accessing your application.

Appendix, An Arsenal of Tools, covers the arsenal of tools that Laravel provides, which haven't been covered in the previous chapters.

What you need for this book

As Laravel is a PHP-based application framework, you will need a code editor or IDE with syntax highlighting for PHP.

We'll be using the Homestead virtual machine, which requires both Vagrant and VirtualBox to be installed on your machine; installation instructions for both of these will be provided later in the book.

Also, if you plan to deploy applications to a live web server, then you will need an FTP client or SSH access to the remote web server in order to move the files from your local machine to the web-accessible server.

Who this book is for

This book is primarily aimed at those interested in learning about the Laravel framework, as maybe they've heard about it but not had the chance or time to become familiar with it. Therefore, knowledge of PHP and related technologies (such as MySQL) is assumed, as is knowledge of object-oriented programming.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The Illuminate namespace does not refer to a third-party library."

A block of code is set as follows:

    - map:
      to: /home/vagrant/Code/
    - furbook

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

Route::post('cats', function() {
  $cat = Furbook\Cat::create(Input::all());
  return redirect('cats/'.$cat->id)
    ->withSuccess('Cat has been created.');

Any command-line input or output is written as follows:

$ composer create-project laravel/laravel --prefer-dist

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: " If you now try to visit an invalid URL, nginx will display a 404 Not Found error page."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.