Book Image

Laravel Application Development Cookbook

By : Terry Matula
Book Image

Laravel Application Development Cookbook

By: Terry Matula

Overview of this book

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 (18 chapters)
Laravel Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Configuring Laravel


After installing Laravel, it's pretty much ready to go without much need for configuration. However, there are a few settings we want to make sure to update.

Getting ready

For this recipe, we need a regular installation of Laravel.

How to do it...

To complete this recipe, follow these steps:

  1. Open /app/config/app.php and update these lines:

    'url' => 'http://localhost/,
    'locale' => 'en',
    'key' => 'Seriously-ChooseANewKey',
  2. Open app/config/database.php and choose your preferred database:

    'default' => 'mysql',
    'connections' => array(
        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'database',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            ),
        ),
  3. In the command line, go to the root of the app and make sure the storage folder is writable:

    chmod –R 777 app/storage
    

How it works...

Most of the configuration will happen in the /app/config/app.php file. While setting the URL isn't required, and Laravel does a great job figuring it out without setting it, it's always good to remove any work from the framework that we can. Next, we set our location. If we choose to provide localization in our app, this setting will be our default. Then, we set our application key, since it's best to not keep the default.

Next, we set which database driver we'll be using. Laravel comes with four drivers out of the box: mysql, sqlite, sqlsrv (MS SQL Server), and pgsql (Postgres).

Finally, our app/storage directory will be used for keeping any temporary data, such as sessions or cache, if we choose. To allow this, we need to make sure the app can write to the directory.

There's more...

For an easy way to create a secure application key, remove the default key and leave it empty. Then, in your command line, navigate to your application root directory and type:

php artisan key:generate

That will create a unique and secure key and automatically save it in your configuration file.