Laravel 5.x Cookbook - Alfred Nutile - E-Book

Laravel 5.x Cookbook E-Book

Alfred Nutile

0,0
41,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

A recipe-based book to help you efficiently create amazing PHP-based applications with Laravel 5.x

About This Book

  • Leverage the amazing new features of Laravel 5.x to create cutting-edge responsive PHP applications.
  • Create apps with interoperability features and extend these features to your existing applications as well.
  • Over 60 recipes that combine tried and tested Laravel tips for getting your app working.

Who This Book Is For

The ideal target audience for this book is PHP developers who have some basic PHP programming knowledge. No previous experience with Laravel is required for this book.

What You Will Learn

  • Optimize Your Gulp and Elixir Workflow
  • Use Travis to run tests with every push
  • Build and test your view-based route in PHPUnit
  • Explore workflows for migrations and seeding
  • Implement Angular in your Laravel applications
  • Set up a user authentication system
  • Integrate the new Billing library and Stripe in your Laravel application
  • Use the Artisan command-line tool
  • Test your App in Production with Behat

In Detail

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.

Style and approach

This book will have a practical recipe-based approach with dedicated recipes on your daily Laravel tasks (as well as on more advanced issues) that will help you become a pro with Laravel 5.x

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 238

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Setting Up and Installing Laravel
Introduction
Setting up Homestead
Getting ready
How to do it...
How it works...
There's more...
See also
Setting composer and PHP on your local machine for faster Workflows
Getting ready
How to do it...
How it works...
There's more...
See also
Setting up your first application in Homestead
Getting ready
How to do it...
How it works...
See also
Using .env for your local build
Getting ready
How to do it...
How it works...
See also
Using sequel pro and connecting to local and remote databases
How to do it...
How it works...
See also
Setting up Gulp and Elixir
How to do it...
How it works...
See also
2. Using Composer Packages
Introduction
Working with Composer install command and avoiding Composer update
Getting ready
How to do it...
How it works...
There's more...
See also
Making a provider
Getting ready
How to do it...
How it works...
See also
Using the Facade pattern
Getting ready
How to do it...
How it works...
See also
Using private packages
Getting ready
How to do it...
How it works...
See also
3. Routing
Introduction
Building an API / JSON based route for searching
Getting ready
How to do it...
How it works…
See also
Testing your route in PHPUnit
Getting ready
How to do it…
How it works…
See also
Building a view based route
Getting ready
How to do it…
How it works…
Testing your view based route in PHPUnit
Getting ready
How to do it…
How it works…
See also
Creating named routes
Getting ready
How to do it…
How it works…
See also
4. Building Views and Adding Style
Introduction
Organizing your Blade files
Getting ready
How to do it...
How it works...
See also
Installing a WrapBootStrap theme
Getting Started
How to do it…
How it works…
See also
Making your authentication pages
How to do it…
How it works…
Implementing an error message template
Getting started…
How to do it…
How it works…
Building your main search page
Getting started…
How to do it…
How it works…
See also
Adding a static page
Getting started…
How to do it…
How it works…
5. Working with Data
Introduction
Setting up users and running migrations
Getting ready
How to do it...
How it works...
See also
Altering a migration
Getting ready
How to do it....
How it works…
See also
Using factories for migrations and tests
Getting ready
How to do it…
How it works…
See also
Using a generator to scaffold your user wishlist area
Getting ready
How to do it…
How it works…
See also
Seeding so you can see how your app looks
Getting ready
How to do it…
How it works…
See also
Adding a file upload to user profile
Getting ready
How to do it…
How it works…
See also
Validating the file upload
Getting ready
How to do it…
How it works…
See also
Saving files to S3
Getting ready
How to do it…
How it works…
See also
6. Adding Angular to Your App
Introduction
Getting ready
How to do it...
How it works...
See also
Adding Angular search to our search page
Getting ready
How to do it…
How it works…
See also
Handling Angular and Ajax requests
Getting ready
How to do it…
How it works…
See also
Paginating our Angular results
Getting ready
How to do it…
How it works…
See also
Testing an Angular page with Behat
Getting ready
How to do it...
How it works…
See also
Creating a relationship with favorites
Getting ready
How to do it…
How it works…
See also
Building a favorites Ajax widget in Angular
Getting ready
How it works…
How to do it…
See also
Validating incoming input
Getting ready
How to do it…
How it works…
See also
Using the CORS protection
Getting ready
How to do it…
How it works…
See also
Using Elixir and Gulp to set up Angular
Getting ready
How to do it...
How it works...
See also
7. Authentication, Security, and Subscriptions
Introduction
Using policies and guard to protect user pages
Getting ready
How to do it...
How it works...
See also
Adding feature flags to hide features from users
Getting ready
How to do it…
How it works…
See also
Implementing Socialite to allow users to login with Facebook
Getting ready
How to do it…
How it works…
See also
Adding custom middleware to protect user admin area
Getting ready
How to do it…
How it works…
See also
Using Laravel to set up a subscription site
Getting ready
How to do it…
How it works…
See also
Creating an interface for the user to manage subscriptions
Getting ready
How to do it…
How it works…
Creating an admin interface for subscriptions
Getting ready
How to do it…
How it works…
8. Testing and Debugging Your Application
Introduction
Generating tests
Getting ready
How to do it...
How it works...
There's more...
See also
Using tests to think through your code TDT (Test Driven Thinking)
Getting ready
How to do it...
How it works...
See also
Getting your code onto GitHub
Getting ready
How to do it...
How it works...
See also
Using VCR for API testing
Getting ready
How to do it...
How it works...
See also
Using Travis to run tests with every push
Getting ready
How to do it...
How it works...
See also
Launching Gulp watch into your workflow
Getting ready
How to do it...
How it works...
See also
Using mockery to test your controllers
Getting ready
How to do it...
How it works…
See also
Troubleshooting your application
Getting ready
How to do it…
How it works…
9. Adding Advanced Features to Your App
Introduction
Building an Artisan command
Getting ready
How to do it...
How it works...
See also
Creating scheduler to notify users of new comics
Getting ready
How to do it…
How it works…
See also
Setting up e-mail notices
Getting ready
How to do it…
How it works…
See also
Adding clean URLS for the users profile page
Getting ready
How to do it…
How it works…
See also
Using pusher for live notifications
Getting ready
How to do it…
How it works…
See also
Adding a blog area to update users on new features
Getting ready
How to do it…
How it works…
See also
10. Deploying Your App
Introduction
Setting up Forge, AWS, and CodeDeploy
Getting ready
How to do it...
How it works…
See also
Setting up Travis to auto deploy when all is passing
Getting ready
How to do it…
How it works…
See also
Working with your .env file
Getting ready
How to do it…
How it works…
See also
Testing your app on Production with Behat
Getting ready
How to do it…
How it works…
See also
Making a composer package out of our client
Getting ready
How to do it…
How it works…
Index

Laravel 5.x Cookbook

Laravel 5.x Cookbook

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2016

Production reference: 1290816

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78646-208-4

www.packtpub.com

Credits

Author

Alfred Nutile

Reviewer

Andrew Cavanagh

Commissioning Editor

Amarabha Banerjee

Acquisition Editor

Reshma Raman

Content Development Editor

Parshva Sheth

Technical Editor

Gebin George

Prajakta Mhatre

Copy Editor

Safis Editing

Project Coordinator

Sheejal Shah

Proofreader

Safis Editing

Indexer

Tejal Daruwale Soni

Graphics

Abhinash Sahu

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Author

Alfred Nutile is an Enterprise Architect and Laravel lead based in Western Massachusetts. He's been working in the industry since the mid 90's. He started in PHP and MySQL back around that time and has worked with Ruby on Rails, Drupal, and Angular along the way. He introduced Laravel into an enterprise web stack, where he is currently contracted at, as Laravel proved itself as an amazing framework to build API's and Angular heavy application.

You can read more about him and checkout his blog at http://www.alfrednutile.info/ or follow him on Twitter at https://twitter.com/alnutile

Make sure to checkout the discount LaraCasts is offering those who buy the book!

Get a coupon for 50% on your first bill. Make it a yearly subscription and save $43!

Coupon Code: LaracastsLovesPackt

https://laracasts.com/signup?plan=yearly&coupon=LaracastsLovesPackt.

First let me say thanks to Taylor Otwell, I moved away from PHP to Rails and really was missing PHP only to be pointed to Laravel and have not looked back since. The framework makes my day to day work a pleasure and sometimes I feel guilty how easy it has made getting work done.

And Jeffrey Way for offering an amazing service that helped me to grow in understanding practical programming skills, keeping things simple, best practices and Laravel.

Of course I would like to thank Andrew Cavanagh for taking time to tediously edit this book. We have worked in the industry together for a number of years and currently both working on Laravel daily. And then there is my family who keeps me from getting too out of balanced since it is so easy to lose myself in the joy of building things on the computer!

About the Reviewer

Andrew Cavanagh is an experienced PHP developer whose background includes Drupal, Laravel, AngularJS, managing *nix servers (Apache and Nginx), project/budget/team management, and general haberdashy. He's currently focused on building enterprise web applications and tools. Andrew also enjoy cooking, amateur mycology, brewing, and long walks in imaginary places.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

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 and more efficient workflows, 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.

What this book covers

Chapter 1, Setting Up and Installing Laravel, helps you setup Laravel on your local machine.

Chapter 2, Using Composer Packages, this will cover some key concepts to getting comfortable with this amazing tool.

Chapter 3, Routing, the heart of any web framework, this will dig into some use cases of Laravel routing.

Chapter 4, Building Views and Adding Style, digging into Blade, Bootstrap and other key areas to building an app.

Chapter 5, Working with Data, covers factories, seeding and a look at a scaffolding library to save you work.

Chapter 6, Adding Angular to Your App, all the key concepts to getting going with Angular in your application.

Chapter 7, Authentication, Security, and Subscriptions, covers protecting your application, building a subscription service, and an admin interface.

Chapter 8, Testing and Debugging Your Application, shows you how to think about your code using tests, having TravisCI run your tests on every push to Github, and more.

Chapter 9, Adding Advanced Features to Your App, teaches you about building Artisan commands, Scheduler, Clean URLs and more.

Chapter 10, Deploying Your App, this chapter will dig into CodeDeploy, Forge, TravisCI and other recipes to deploy your application.

What you need for this book

The entire list of this and the installation process has been explained in Chapter 1 of the Book.

Who this book is for

The ideal target audience for this book is PHP developers who have some basic PHP programming knowledge. No previous experience with Laravel is required for this book.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

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: "You will need a terminal application, access to the Git command"

A block of code is set as follows:

public function __construct(ClientInterface $client) { /////

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

>rm –rf composer.lock vendor>composer install

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: "First navigate to GitHub, Settings, and Personal access tokens."

Note

Warnings or important notes appear in a box like this.

Tip

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 <[email protected]>, 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 www.packtpub.com/authors.

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 for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Laravel-5x-Cookbook/. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

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 http://www.packtpub.com/submit-errata, 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 https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

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 <[email protected]> with a link to the suspected pirated material.

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

Questions

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

Chapter 1. Setting Up and Installing Laravel

In this chapter, we will cover the following topics:

Setting up HomesteadSetting up composer and PHP on your local machine for faster WorkflowsUsing .env for your local buildUsing sequel pro and connecting to local and remote databasesSetting up your first application in HomesteadSetting up Gulp and Elixir

Introduction

In this chapter, we will cover installing and setting up Laravel and Homestead. As I have often said in this book, the online Laravel docs are great, and I will refer to them as needed. This book should be regarded as a complement to the official documentation, expanding on the explanations found there and adding some tips and tricks for everyday use. Also, I will show a number of shortcuts to help speed up your workflow. Finally, I will touch on Gulp and Elixir.

Setting up Homestead

This section will work off the existing Laravel docs to make sure your Homestead is set up correctly, as well as give you some background as to what is going on.

Getting ready

You will need a terminal application, access to the Git command, and decent Internet. As for the terminal on Mac, I suggest iTerm, available at https://www.iterm2.com/; it really is a nice tool for something you are going to use quite often. For Windows, git for Windowshttps://git-for-windows.github.io/ got me going quickly both for git and a Bash such as terminal. Linux has a nice terminal to begin with, and installing git is easy. As far as Vagrant and VirtualBox are concerned, I will link you to the related sites since they do a good job at explaining how to install each of them on your system.

How to do it...

The following are the steps to set up Homestead:

First, install VirtualBox as noted on their site at https://www.virtualbox.org/wiki/Downloads.Once this is in place, install Vagrant from https://www.vagrantup.com/.

At this point, Vagrant will be ready to use at the command line:

You will not really need to open VirtualBox.

Tip

For Windows users, this link helped me a lot to get started with Homestead: http://blog.teamtreehouse.com/laravel-homestead-on-windows.

Make a folder in your home directory called Code with a capital C.

On a Mac, this will look like—/Users/alfrednutile/Code.

From here, the online docs do a great job of getting you going on the final Homestead installation and setup—https://laravel.com/docs/5.2/homestead.

How it works...

When done, you will have the Homestead.yml configuration information in the ~/.homestead folder to modify as needed. On Mac, this would be /Users/alfrednutile/.homestead/Homestead.yml.

Tip

Laravel Docs talk about shortcuts in the Daily Usage section at https://laravel.com/docs/5.2/homestead#daily-usage.

Also, you should have made a new folder called ~/Code to be the base folder for all your projects. For example, my folder looks like this:

/Users/alfrednutile/Code/app1/Users/alfrednutile/Code/app2

You can have multiple applications within your code folder. In this example, app1 is the root folder for the app1 application, and app2 is the root folder for the app2 code. Keep in mind that the Vagrant box will later on mount this Code folder into the /home/vagrant/Code folder inside the Vagrant client.

Tip

I do my migration and PHPUnit work inside Homestead using the ssh shortcut that the online documents show you. But I do a lot of work outside Homestead inside the Code/app1 directory, such as all the Git commands and much of composer. This creates a much faster workflow for the file intense commands.

There's more...

You can, of course, manually set up your own machine for Nginx, PHP, MySQL, and all the rest, but there are a lot of reasons why the preceding one is best. On a team or alone, having your environment contained like this makes upgrading your machine, going from desktop to laptop, pushing code to production, having up-to-date libraries for new apps and older libraries for legacy apps, and more so much easier.

See also

Laravel: https://laravel.com/docs/5.1/homestead.Vagrant: https://www.vagrantup.com/VirtualBox: https://www.virtualbox.org/wiki/Downloads

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...

Type the following in the terminal:
>cd ~/Code
Then, download Laravel to a new folder:
>composer create-project --prefer-dist laravel/laravel recipes
Move into the directory for your new application:
>cd recipes
Now we need to tell Homestead about our new application:
>cd ~/.homestead && subl Homestead.yml