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

Setting up your first application in Homestead


In this section, we will download Laravel and set up our local site to use for the rest of our recipes taking advantage of Homestead.

Getting ready

We have Homestead installed. My home folder called ~/Code is where we will be working.

How to do it...

  1. Type the following in the terminal:

    >cd ~/Code
    
  2. Then, download Laravel to a new folder:

    >composer create-project --prefer-dist laravel/laravel recipes 
    
  3. Move into the directory for your new application:

    >cd recipes
    
  4. Now we need to tell Homestead about our new application:

    >cd ~/.homestead && subl Homestead.yml
    
  5. Once the editor pops open, you can add your new site:

  6. Under database:

  7. Click on Save and close the editor.

  8. Then, start up Homestead or just provision it:

    >homestead provision
    

    You may be asked for a password, which is your system admin password and not the Homestead password.

  9. Then, we need to edit our system Host file (in this case, our local computer and not Vagrant and Homestead); this will again ask for our system password:

    >sudo subl /etc/hosts
    

    Tip

    I will show a shortcut command in the How it works… section.

  10. Next, edit the host file to set your recipes.dev domain right next to the default Homestead IP of 192.168.10.10; then, save and close the editor:

  11. Then, visit your site at https://recipes.dev! You may get an SSL warning but click on Advanced and Proceed:

How it works...

The composer command that we ran gets Laravel from its database of applications and libraries at https://packagist.org/ then download it. We began by installing Homebrew to make installing packages easier. We will periodically need to install packages such as Wget, Webdriver, and more as we progress through this book. Using the brew command supplied by Homebrew makes installing these packages a snap.

I also used some shortcuts. One shortcut was subl, which was what you get when you install http://www.sublimetext.com/. But you can use whatever editor you want.

Using some of the preceding tips will make a shortcut called hedit adding to my ~/.bash_profile:

alias homesteadedit='cd ~/.homestead && subl Homestead.yml'

So, we are editing the main file that Laravel uses for all its Homestead settings. You will be here a lot, so shortcuts really pay off.

The same is applicable with the hostedit command that I used:

alias hostedit='sudo subl /etc/hosts'

Here, we are adding to our .bash_profile a quick way to edit the file and add the needed domain recipes.dev and save and exit. Now, when you visit https://recipes.dev, your operating system will know that it is really for Homestead.

See also