Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Laravel 5.x Cookbook
Laravel 5.x Cookbook

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

Arrow left icon
Profile Icon Matula Profile Icon Nutile
Arrow right icon
€18.99 per month
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2 (6 Ratings)
Paperback Sep 2016 402 pages 1st Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Matula Profile Icon Nutile
Arrow right icon
€18.99 per month
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2 (6 Ratings)
Paperback Sep 2016 402 pages 1st Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Laravel 5.x Cookbook

Chapter 2. Using Composer Packages

In this chapter, we will cover the following topics:

  • Working with the composer install command and avoiding the Composer update
  • Downloading and installing Guzzle using Composer
  • Making a provider
  • Using the Facade pattern
  • Using private packages

Introduction

We will cover some of the day-to-day workflows of setting up Laravel to use composer and many of the packages that exist out there for us to easily use in our PHP applications.

Working with Composer install command and avoiding Composer update

Composer is an amazing tool in PHP which allows us to pull in libraries from https://packagist.org/ and even our own private repositories. We will cover how to install a library and note some steps to save time.

Getting ready

We covered installing Composer on your Mac in Chapter 1, Setting Up and Installing Laravel, though you can use it inside Homestead if you need to.

How to do it...

Perform the following steps to install Guzzle using Composer:

  1. In this example, we will use Composer to install Guzzle (a powerful PHP HTTP client). Make sure you are in your App directory, and in this example, I will be on my local computer and not in Homestead just to make the file processing go faster:
    >composer require "guzzlehttp/guzzle":"^6.1"
    

    This will take a minute or less to run.

  2. And that is it!

How it works...

First, let me say this is a good example of a short tip, which is better than a long one. Maybe other instructions...

Making a provider

In the previous section, we used composer to pull in Guzzle, so we're ready to use it in our project. However, we'd rather not have to instantiate the Guzzle client manually every time we invoke it—hardcoding URLs and authentication and settings with each use. A service provider can help to centralize some of this configuration, and later, we will use service providers to help swap in a mock implementation for testing purposes.

Providers can also help us to avoid writing code that directly calls to a service, which is often a very helpful practice. For example, we may make BillingProvider that can use either Swipe or BrightTree as a billing service. BillingProvider allows us to easily switch between different implementations of the billing service.

Getting ready

Follow the steps in the Working with Composer install command and avoiding composer update section to pull in Guzzle, and start up your terminal.

How to do it...

The following steps will help you in...

Using the Facade pattern

Using the preceding work, let's take it one step further in how easy it is to use this Client in our code.

Getting ready

Install Guzzle and set up the provider just as we did previously, and you are ready for this next recipe.

How to do it...

  1. Make a folder called Facades in your app folder.
  2. Then add a file called APIClient.php and make it look like this:
    How to do it...
  3. Then scroll way down to the Façade section of this file, where we can register the Facade in our config/app.php file like this:
    How to do it...
  4. Now, let's see it working in a test by adding the method called seeing_our_facade_work to our test:
    How to do it...
  5. Now run the test:
    How to do it...

How it works...

So, the amount of work is all it takes to make your Provider just as easy to use as View, File, Storage, and all the other Facades that come from Laravel that make it easy and enjoyable to use.

Also, we can change the test to show it being just as easily swapped out. We will cover this in the testing chapter.

See also

  • Laracasts and another great video from...

Using private packages

Sometimes, you need to use a private repository on GitHub or another location. I will cover here how to set this up in your composer.

Getting ready

We need a private repo, so if you have it and its composer.json is set up properly, you will be set from there.

How to do it...

  1. First, go to GitHub and navigate to SettingsPersonal access tokens:
    How to do it...
  2. At the command line, type this:
    >composer config –g github-oauth.github.com THE_TOKEN_FROM_ABOVE.

  3. Then, edit composer.json so that there are two new sections:
    How to do it...
  4. Then, let's tell the composer to install this:
    >rm –rf composer.lock vendor
    >composer install
    

How it works...

Alright, let's talk about these steps. The first one is to make sure we are setting up our Homestead or Mac for easy access to the private repository. This is really key as well if you are doing 2FA on your GitHub account (which you should be doing). Step 2 wraps this up by adding it to your ~/.composer configuration.

In the...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 14, 2016
Length: 402 pages
Edition : 1st
Language : English
ISBN-13 : 9781786462084
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 14, 2016
Length: 402 pages
Edition : 1st
Language : English
ISBN-13 : 9781786462084
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Full-Stack Vue.js 2 and Laravel 5
€36.99
Laravel 5 Essentials
€24.99
Laravel 5.x Cookbook
€41.99
Total 103.97 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Setting Up and Installing Laravel Chevron down icon Chevron up icon
2. Using Composer Packages Chevron down icon Chevron up icon
3. Routing Chevron down icon Chevron up icon
4. Building Views and Adding Style Chevron down icon Chevron up icon
5. Working with Data Chevron down icon Chevron up icon
6. Adding Angular to Your App Chevron down icon Chevron up icon
7. Authentication, Security, and Subscriptions Chevron down icon Chevron up icon
8. Testing and Debugging Your Application Chevron down icon Chevron up icon
9. Adding Advanced Features to Your App Chevron down icon Chevron up icon
10. Deploying Your App Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
(6 Ratings)
5 star 0%
4 star 16.7%
3 star 0%
2 star 50%
1 star 33.3%
Filter icon Filter
Top Reviews

Filter reviews by




Noel Falcon Apr 18, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good content
Amazon Verified review Amazon
KaylaKaze Aug 10, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Word of advice: if you're writing a programming book, make your screenshots using a WHITE background on your IDE.
Amazon Verified review Amazon
MJW Oct 11, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I'd be able to give it more stars if I could read the code examples. Unfortunately they have been take from screenshots of a code editor with a dark profile, so some code is indistinguishable from the background.The content may be great, but in terms of print and presentation, is not as good as the O'Reilly 'Cookbook' series.
Amazon Verified review Amazon
RK Oct 03, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
The code printed is very small for a number of snippets with white text merged into black background.. Whose idea black ?..REALLY not readable. .
Amazon Verified review Amazon
Amazon Customer Aug 24, 2021
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
I guess it was my fault really. I was looking for a good book for beginners but made a wrong purchase. The author is a programmer and not a teacher . Most of the content made assumptions that you were an advanced user of Laravel. The only concession wa the first chapter where you were introduced to the basic setup., and even for half of that chapter the reader is sent away somewhere or the other to get how-to information. I could have saved my money and downloaded free tutorials instead...which I eventually did . From the second chapter to the end the author was completely immersed in displaying his brilliance at programming and on his brilliant project he is working on in this Cookbook. It is a distressing book . I'd possibly eventually use it as a door stop. It is that heavy !
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.