Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nicola Malizia:
Understanding Laravel’s Automatic Facades
Mar 27, 2017 @ 09:24:36

On his Unnikked site Nicola Malizia has written up a post sharing some insight into how Laravel's automatic facades work, a feature that was introduced in Laravel v5.4.

Another cool feature shipped with the release of Laravel 5.4 is the ability to use Facades on the fly. Automatic Facades with the official documentation is quite informative. So I assume you are familiar with them.

He then starts in on the creation of custom facades: defining the functionality (a class), creating the facade and updating the app config to load it in. He then covers what's happening behind the scenes when the "Facades" namespace is loaded and the facade is called (lots of code snippets included here).

My suggestion is to start using automatic facades whenever is possible, their impact is negligible. To see when to use facades in general a good read is available in the official documentation.
tagged: laravel automatic facade tutorial introduction

Link: https://unnikked.ga/understanding-laravels-automatic-facades-d623e4774e5f#.hi2vq6igs

SitePoint PHP Blog:
My Laravel Package Building Workflow
Mar 20, 2017 @ 11:19:04

On the SitePoint PHP blog they've posted a tutorial from author Francesco Malatesta covering his Laravel package building workflow.

Packages are a really important part of the Laravel experience (just like with any other framework). Whatever we need to do, there’s probably already a package for it out there; ready for a composer require to bring some magic in.

Some weeks ago, I had an idea for a new one. I work for AdEspresso, where we have a Symfony FeatureBundle, which handles feature toggling in our projects. It’s a really nice piece of code that we use to release new features only for specific subsets of users. So, I asked myself… why not port it for Laravel? That’s how my Laravel Feature package idea was born.

[...] In this article, I will try to explain how I prepared my development environment for it, and which choices I made when building the package. Not the development of every line of code per-se, but the actual workflow of getting from nothing to a full package.

He starts by talking about a handy addition to an application that can make the rollout of your new package easier: feature flags. He then starts in talking about the Composer configuration of the package and its "skeleton" (default directory and file structure). The tutorial then starts in on the code in the package itself covering the abstraction of domain code and implementing the features including the configuration, Blade template and the matching facade.

tagged: laravel package workflow tutorial skeleton featureflag implementation

Link: https://www.sitepoint.com/laravel-package-building-workflow/

Esben Petersen:
A modern REST API in Laravel 5 Part 4: Authentication using Laravel Passport
Mar 20, 2017 @ 10:56:15

Esben Petersen has posted the fourth part of his tutorial series covering the creation of a "modern REST API" with Laravel. In this latest article he focuses on authenticating users with the help of an OAuth2 flow.

OAuth is all around us. Most of us have tried to login to a 3rd party service using our Facebook or Google account as a login. This login mechanism is one of many OAuth authentication types. However, you can also use OAuth to generate simple API keys. One of the OAuth authentication types generates API keys based on username and password and is therefore a solid authentication choice for SaaS-style apps. This article will explore how to setup the password grant authentication type in Laravel using Laravel Passport.

The article is broken up into a few different sections, each with explanations and code where appropriate to help illustrate the point:

  • a basic introduction to OAuth2 and grants
  • authentication in single-page applications
  • dependencies to use (and install/configuration)
  • creating the login proxy
  • building a consumer

The final step is an example (using a curl command) to test the API and ensure things are working as expected. The post ends with a more "real world" example of a Slack-style application and linking channels and user but only showing the channels users have access to based on scope.

tagged: tutorial rest api laravel series part4 oauth2 passport

Link: http://esbenp.github.io/2017/03/19/modern-rest-api-laravel-part-4/

Matt Stauffer:
Removing all Vue dependencies from Laravel
Mar 15, 2017 @ 10:17:01

In a new tutorial on his site Matt Stauffer shows how to remove the Vue.js dependencies from a standard Laravel installation. There's only a few but they're installed by default and if you're not using Vue.js they can easily be removed.

The recent versions of Laravel have come with some very minor Vue dependencies out of the box. They're easy to remove, but you may have not actually tried that yet, or you might be worried you're going to leave something sitting there. So, here's a quick tip on how to remove all Vue dependencies in a new Laravel install in a few easy steps.

The process is broken down into a few steps:

  • Install Laravel
  • Drop Vue from package.json
  • Drop the bootstrap and the sample component

The changes you'll need to make to the configuration files are included so the removal process is pretty painless.

tagged: laravel remove vuejs tutorial steps javascript

Link: https://mattstauffer.co/blog/removing-all-vue-dependencies-from-laravel

SitePoint PHP Blog:
The Android Elephpant - Laravel on your Android Phone?
Mar 14, 2017 @ 13:06:05

On the SitePoint PHP blog there's a new tutorial posted with an interesting idea for the use of PHP - running it on an Android phone (a Laravel application specifically).

It was not that long ago that Christopher Pitt wrote an excellent article about writing and running PHP code on an iPad. After reading it, I thought to myself "It would be really cool to do the same on Android": being able to write and edit code on the fly, for example while traveling, and not having to take the laptop everywhere. So I’ve decided to do some research and see what I could come up with.

For this article, you can use any type of Android device. I’ve done it on my phone, but an Android tablet with a Bluetooth keyboard would probably be the ideal setup.

Using the Termux application and using it to install various packages for both development and PHP usage. They also install Vim, Git and Composer to make package management easier. Once the environment is installed it moves on to the Laravel installation (that works just fine), installing SQLite for the database and building out the user authentication and authorization handling with Laravel's "make:auth" artisan command.

tagged: android tutorial phone laravel install configuration

Link: https://www.sitepoint.com/android-elephpant-laravel-android-phone/

Nicola Malizia:
Understanding Laravel’s HighOrder Collections
Mar 14, 2017 @ 09:11:59

Nicola Malizia has written up a tutorial that helps to explain Laravel's HighOrder collection functionality, a feature that was added in Laravel 5.4.

A new version of Laravel is available from 24 January 2017 and, as usual, it comes with a lot of new features.

Among them, there is one that takes advantage of the dynamic nature of PHP. Some out of there will contempt this, but I find it awesome!

He talks briefly about what the normal Collection class provides and provides an example of creating a collection and using the "map" function to return an average. With the new functionality the methods can be called directly on the collection with a simplified format. With the example out of the way he then dives into the source code for the feature, showing how it defines the "proxy" methods allowed and uses the __get and __call magic methods to map the method calls back to a collection.

tagged: laravel highorder collection tutorial introduction code

Link: https://unnikked.ga/understanding-laravels-highorder-collections-ee4f65a3029e#.uo1gmhbgu

Esben Petersen:
A modern REST API in Laravel 5 Part 1: Structure
Mar 09, 2017 @ 10:44:56

Esben Petersen has kicked off his series on creating a modern REST framework in Laravel 5 with part one in the series. This first tutorial focuses on the setup of the application using a "folders by component" approach.

Over time when your API grows in size it also grows in complexity. Many moving parts work together in order for it to function. If you do not employ a scaleable structure you will have a hard time maintaining your API. New additions will cause side effects and breakage in other places etc.

It is important to realize in software development no singular structure is the mother of all structures. It is important to build a toolbox of patterns which you can employ given different situations. This article will serve as an opinionated piece on how such a structure could look.

The tutorial covers structure on three different levels (patterns): application flow, project folder structure and resource folder structure. For each level they cover some of the basic concepts involved and share code showing how it could be implemented including controllers, repositories, middleware and fitting it all into a a resource folder structure.

tagged: laravel rest api laravel5 tutorial series part1 structure

Link: http://esbenp.github.io/2016/04/11/modern-rest-api-laravel-part-1/

Scotch.io:
Get Started Running Laravel in a Docker Container
Mar 07, 2017 @ 14:07:28

The Scotch.io blog has a new tutorial posted showing you how to get a Laravel application up and running in a Docker container with a minimal amount of work. The article assumes you already have a working knowledge of Laravel and Docker, so if you're not familiar with those you'll need to read up there first.

Laravel and Docker are two very popular tools of choice when considering building for the web. Although both of them do very different things, they can both be combined to create amazing products.

For our use case, we will be running Laravel in a Docker container. This is going to be a simple demonstration on how to use both products to create real-life applications. Nothing heavy.

The tutorial starts with some of the prerequisites you'll need before getting started but quickly gets into the commands you'll need to set up your environment. Using a custom Docker container they show you the configuration to get the container set up, how to build the database connection, bring the container up and verify all is working as expected.

tagged: docker laravel container tutorial introduction installation configuration

Link: https://scotch.io/tutorials/get-started-running-laravel-in-a-docker-container

Laravel News:
Installing Laravel in a Subfolder? Hide your .env file.
Mar 06, 2017 @ 09:42:59

On the Laravel News site they've posted an article with some reminders about installing Laravel in a subfolder including "hiding" your .env file.

If you are new to Laravel you might not be familiar with its directory structure and the reasons why it’s setup the way it is. If you look at the main repository it’s setup like this, and the documentation covers what each of these folders handles.

What is important here is the “public” folder. That is the ONLY directory you want to be exposed through the web. Everything else should be outside of your web root, this way people can’t access any of your important files through the browser.

He gives an example of an instance where a site was in a subfolder and, just by changing the URL, he was able to locate (and view!) the .env file complete with sensitive information. The rest of the post gives instructions on installing it in a subfolder, moving around a few folders and updating the front controller to change the autoload and bootstrap locations.

tagged: laravel subfolder sensitive data install tutorial

Link: https://laravel-news.com/subfolder-install

Laravel News Podcast:
Episode #32 - Laravel Shift with Jason McCreary
Mar 03, 2017 @ 11:14:52

The Laravel News site has announced the release of the latest episode of the Laravel News podcast, hosted by Jacob Bennett and Michael Dyrynda - Episode #32: Laravel Shift with Jason McCreary.

Jake and Michael speak with Jason McCreary about Laravel Shift, LTS software, and getting git.

Topics mentioned in this episode include:

You can listen to this latest episode either through the in-page audio player or by downloading the mp3 directly. If you enjoy the show be sure to subscribe to their feed and follow Laravel News on Twitter for updates when new shows are released.

tagged: laravelnews laravel podcast ep32 laravelshift jasonmccreary

Link: https://laravel-news.com/podcast/32