Book Image

Laravel Starter

By : Shawn McCool
Book Image

Laravel Starter

By: Shawn McCool

Overview of this book

<p>Laravel is fundamentally changing the PHP web-development landscape. Laravel is bringing the paradigm-shifts that PHP developers have been craving. We now can take control of our application architecture and advance our craft without needing to fight against our tools. Laravel&rsquo;s philosophy is to provide a highly flexible architecture and an extremely expressive API while emphasizing PHP&rsquo;s strengths and abstracting out its weaknesses. For these reasons Laravel is ideal for quickly creating high performance, robust applications. By providing developers with tools for automating tasks including database schema modification, CRUD operations, and testing we&rsquo;re able to reduce our workload, application complexity, and human-error.<br /><br />"Laravel Starter" is the ideal introduction to this game-changing framework. Learn best-practiced approaches to web-application development with Laravel from a seasoned professional.<br /><br />It starts out by installing and configuring the framework step-by-step. Then you&rsquo;ll use Laravel best-practices to create a private user administration system that is ready for real-world use. The later part deals with digging deep into Eloquent relationships, exploring the different relationship types and how Eloquent is working under-the-hood to simplify your life without forcing you to relinquish control. Exploring Laravel&rsquo;s simple yet flexible authentication system, data validation, and filters allows you to easily run code before and after your controller actions. Finally, it discusses Laravel bundles, the most flexible PHP modular code implementation in its weightclass.<br /><br />Focused on the how as much as the why, Laravel Starter gives you the tools to immediately begin creating professional web-applications with Laravel.</p>
Table of Contents (8 chapters)

Installation


In five easy steps, you can install Laravel and get it set up on your system.

Step 1 – What do I need?

Before you install Laravel, you will need to check that you have all of the required elements, as follows:

  • Laravel requires a web server environment and will run in Apache, IIS, and Nginx easily. Laravel should run in any server environment that supports PHP. The easiest way to set up a local webserver for development is to install XAMPP (Windows), MAMP (Mac OSX), or Apache with PHP5 on through a package manager on Linux.

  • Laravel is written in the PHP scripting language. Currently, Laravel v3.2.5 requires a minimum of PHP v5.3 to run.

  • Laravel requires that you have the FileInfo and Mcrypt libraries installed. Conveniently, they are almost always installed by default.

  • .For our QuickStart application we require a database. Out of the box, Laravel supports MySQL, MSSQL, PostgreSQL, and SQLite.

Step 2 – Downloading Laravel

The easiest way to download Laravel is as a compressed package from http://laravel.com/download.

Alternatively, you can download Laravel by cloning its git repository from GitHub.com with the following command.

git clone [email protected]:laravel/laravel.git

It would be better that you download the most current stable build.

Extract the contents of the compressed package into the directory that you store your web-applications. Typical locations include /Users/Shawn/Sites, c:\sites, and /var/www/vhosts/ depending on your operating system.

We'll assume that your first Laravel installation is in c:\sites\myfirst\.

Step 3 – Configuring hosts

Let's go ahead and set up our web server to host our site. We need to choose a host name for our example application. This is our first application and we're working on our local development environment, so let's use http://myfirst.dev?.

In Linux and OSX, simply add the following line to your /etc/hosts file:

127.0.0.1 myfirst.dev

Windows users should add that line to their c:\windows\system32\drivers\etc\hosts file.

Now you should be able to ping myfirst.dev and see that it resolves to 127.0.0.1.

Step 4 – Setting up your VirtualHost

Now that we have a host name we need to tell our web server where to find the Laravel installation. Add the following VirtualHost configuration to your Apache web server configuration and replace DocumentRoot with the path to your Laravel installation's public directory.

<VirtualHost *:80>
  ServerName myfirst.dev
  DocumentRoot c:/sites/myfirst/public
</VirtualHost>

It's very important to note that DocumentRoot points to the Laravel's public directory. There are multiple security reasons for this. A momentary server misconfiguration can expose the secure information, such as your database passwords.

Step 5 – Restarting your web server and testing

Now that you've installed the Laravel files, added your host declaration, and updated your web-server configuration you're ready to go! Restart your web-server software and go to http://myfirst.dev in your browser. You should see the Laravel splash page!

And that's it!

By this point, you should have a working installation of Laravel and are free to play around and discover more about it.