Book Image

Laravel 5.x Cookbook

By : Terry Matula, Alfred Nutile
Book Image

Laravel 5.x Cookbook

By: Terry Matula, Alfred Nutile

Overview of this book

Laravel is a prominent member of a new generation of web frameworks. It is one of the most popular PHP frameworks and is also free and an open source. Laravel 5 is a substantial upgrade with a lot of new toys, at the same time retaining the features that made Laravel wildly successful. It comes with plenty of architectural as well as design-based changes. The book is a blend of numerous recipes that will give you all the necessary tips you need to build an application. It starts with basic installation and configuration tasks and will get you up-and-running in no time. You will learn to create and customize your PHP app and tweak and re-design your existing apps for better performance. You will learn to implement practical recipes to utilize Laravel’s modular structure, the latest method injection, route caching, and interfacing techniques to create responsive modern-day PHP apps that stand on their own against other apps. Efficient testing and deploying techniques will make you more confident with your Laravel skills as you move ahead with this book. Towards the end of the book, you will understand a number of add-ons and new features essential to finalize your application to make it ready for subscriptions. You will be empowered to get your application out to the world.
Table of Contents (17 chapters)
Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using .env for your local build


This was one of the best changes to Laravel from version 4 and 5 in my opinion. When I was doing Ruby on Rails work, it also had this feature, and this is the key to help create an application that falls in the Twelve Factor App workflow. You will learn how to use this file for setting keys to some recipes later on in the book. In this example, we will start using it to set up our database.

For the rest of this book, I will use PHPStorm for my editor, which helped me a ton to explore Laravel and PHP code when I first started. Make sure your editor has plugins to easily click and explore classes.

Getting ready

When you installed Laravel, it copied the .env file into place. So, just open your editor of choice and open the application directory.

How to do it...

  1. Open .env in your editor.

  2. Alter the file as follows, so the database name and the URL match what we would put in our Homestead setup file:

How it works...

First of all, this is a hidden file. The . in front of it makes it hard to see in File Managers and even the command line. When at the command line, ls -a * is how to show this hidden file. Most code editors or IDEs will show you these.

Also note that Laravel comes with a .gitignore file that includes this file:

We will have to consider the addition or changes of any settings in env, as we push this application to Production for everyone to see when we are done. I will cover this more in Chapter 10, Deploying Your App.

So, what did we change in this file? Most of what you see was already there; we just set two things:

  • DB_DATABASE=recipes_local

  • APP_URL=https://recipes.dev

This is it, really! If you look back, this is what we set in the Homestead.yml file. You can see what we called the database and domain name. So now we need to tell our application what database table to use and which Homestead is made for us. Yeah, for Homestead!

See also