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

Laravel News:
Invisible reCAPTCHA Integration With Laravel
Jun 09, 2017 @ 09:46:15

On the Laravel News site, there's a new post showing you how to use Google's invisible reCAPTCHA in a Laravel application with the help of the "albertcht/invisible-recaptcha" package.

Invisible reCAPTCHA is an improved version of reCAPTCHA v2 (No CAPTCHA) developed by Google, and users now only need to click the button: “I’m not a robot” to prove they are human.

In Invisible reCAPTCHA, there is no longer an embedded CAPTCHA box for users to interact with. It’s totally invisible with only a badge showing on the bottom of the page so users your website know you are using this technology. (The badge can be hidden, but this is not recommended.)

They start with an example of what the output looks like attached to a form and how to install and configure the package. This requires API credentials from the Google side: a sitekey and secretkey. The post finishes with the code you'll need in your forms and as a validator to check the reCAPTCHA code in the response.

tagged: laravel turorial invisible recaptcha integration package

Link: https://laravel-news.com/invisible-recaptcha-integration-with-laravel

TutsPlus.com:
Programming With Yii: Generating Documentation
Jun 02, 2017 @ 11:14:03

The TutsPlus site has posted the latest article in their "Programming with Yii" tutorial series, this time covering the generation of documentation for the API code that's been created to power the application.

Recently, I wrote about building REST APIs for your Yii application and expanded custom APIs for our startup series application, Meeting Planner.

In today's tutorial, I'll introduce you to Yii's apidoc extension, which automatically generates browsable documentation for your code. I'm going to use it to generate API documentation for Meeting Planner.

The tutorial starts off with helping you get the extension installed (via Composer) and links to a few examples of the end result. The tutorial then goes through how to add your own comments to your current files that will be output in the final result directly. This includes open text descriptions and other DocBlock information. It then shows how to generate the documentation, how to navigate the resulting HTML pages and some examples of what it will look like for the current code.

tagged: programming yii2 generate documentation tutorial series package

Link: https://code.tutsplus.com/tutorials/programming-with-yii-generating-documentation--cms-27899

Michael Dyrynda:
Elegant form handling in Laravel
Jun 01, 2017 @ 09:26:26

Michael Dyrynda has written up a new post for the Laravel users out there showing an elegant form handling method he's come up with that doesn't involve the use of the older version of the Laravel Collective HTML package.

On episode 28 of the North Meets South Web Podcast, Jake and I were discussing packages that we always pull into our Laravel projects. Jacob mentioned that he still uses the Laravel Collective HTML package, which was forked from the functionality that was present before Laravel 5, which is something I suggested I hadn't done for a long time.

[...] Jacob went on to explain that a big part of using the form package is because it handles binding form data directly to the forms for you, allowing you to separate form inputs from the create / edit components themselves. [...] I suggested that you can go about this simply enough in your applications by using a combination of the old() helper method and an empty model.

He includes code examples of both ways to generate the form, first using the Collective package then using just the old() helper function to repopulate the form values when the page is rendered. He points out that using this internal method doesn't require yet another package. There are some niceties that are missed with going with the old() method, but there are benefits too.

tagged: laravel form handling package collective tutorial old

Link: https://dyrynda.com.au/blog/elegant-form-handling-in-laravel

SitePoint PHP Blog:
Re-Introducing Symfony Console – CLI PHP for the Uninitiated!
May 25, 2017 @ 11:38:02

The SitePoint PHP blog has posted a tutorial from author Claudio Ribeiro that wants to re-introduce you to the Symfony Console package, a component of the larger Symfony framework that makes it easier to create and work with command-line PHP scripts.

As software developers, we often feel the need to resort to command line tools. These kinds of tools are helpful when we need to do a sort of recurring task like migrating data, performing imports, or creating cron jobs.

The Symfony Console component tool provides us with a simple framework to create our own command line tools. Unlike many components in Symfony, this is a standalone package and is used by the likes of Laravel‘s Artisan and many other famous PHP packages.

The tutorial then walks you through the installation process, via Composer, and the creation of a new command. With this simple base created, he then adds in actual functionality, building out a command to hash and verify a password string. They show how to use the command and an example of its output. Next up, he creates another command example, this time verifying the password hash provided as an argument. The tutorial wraps up with a look at testing your console comamnds with PHPUnit tests via the included CommandTester functionality.

tagged: symfony console commandline cli package component tutorial introduction

Link: https://www.sitepoint.com/re-introducing-symfony-console-cli-php-uninitiated/

North Meets South Podcast:
Episode #28 - Eloquent observers, managing client expectations, and Larav
May 23, 2017 @ 11:32:26

In the most recent episode of the North Meets South podcast - Episode #28 - hosts Jacob Bennett and Michael Dyrynda talk about Laravel. More specifically they cover Eloquent functionality, client expectations, and packages.

In this episode, Jake and Michael talk about Eloquent observers and answer listener questions about managing client expectations and packages we use in our Laravel applications.

Other topics mentioned in this episode include Dash (the documentation tool), the "Supercharge Your Tinker Workflow" article and the Sentry package for Laravel. You can listen to this latest show either using the in-page audio player or by downloading the mp3 directly for listening offline. If you enjoy the show, be sure to subscribe to their feed and follow them on Twitter to get the latest updates when new shows are released.

tagged: northmeetssouth podcast ep28 eloquent observer client expectations laravel package

Link: http://www.northmeetssouth.audio/28

SitePoint PHP Blog:
Re-Introducing Composer – the Cornerstone of Modern PHP Apps
May 22, 2017 @ 11:54:48

If you've been developing any kind of PHP applications lately, chances are you've at least heard of Composer. This package manager has dramatically changed the way we develop in PHP but there are still some out there wondering what all the fuss is about. In this tutorial from SitePoint author Claudio Ribeiro (re-)introduces this powerful tool and provides some basics of its use.

In this article, we will tackle the basics of Composer, and what makes it such a powerful and useful tool.

Before we go into detail, there are two things that we need to have in mind: what Composer is [and] what Composer is not. [...] Essentially, Composer allows you to declare and manage every dependency of your PHP projects.

He then walks you through the installation of the tool, running it either globally or locally (per-project). He lists out some of the basic commands, what they're for and helps you on your way to installing your first package: PHPUnit. He also covers the special "vendor" folder Composer creates, how autoloading works, various configuration values and installing packages globally rather than just locally. He then talks about the other side of the PHP package ecosystem: Packagist including how to submit packages and set up your own package's composer.json so it can be pulled in correctly.

tagged: composer introduction basics tutorial package packagist

Link: https://www.sitepoint.com/re-introducing-composer/

Zend Framework Blog:
Leverage Zend Component Plugin Managers in Expressive
May 19, 2017 @ 09:58:15

The Zend Framework blog has a new post from project lead Matthew Weier O'Phinney showing how you can use plugin managers in Expressive and how it can be used to integrate other components.

With the release of Expressive 2, one of the key stories was the ability to require ZF components within Expressive, and have their dependencies auto-wired into your application courtesy of the component installer.

However, we recently had a user in our Slack channel (need an invite?) indicating they were having issues with usage of custom validators, filters, and input filters. After a <a href=https://discourse.zendframework.com/t/validatormanager-not-calling-custom-validator-factory/109">more thorough writeup on our forums, I realized we'd missed something important when making these integrations, and set out to solve it.

The article then starts with the problem that they're trying to solve, mostly around configuration handling. The solution involved some work done on various packages (like zend-log, zend-filter and zend-form) to make the configuration loading a bit more automated (and with fallback handling).

tagged: zendexpressive module component manager update package

Link: https://framework.zend.com/blog/2017-05-18-plugin-managers.html

Scotch.io:
User Authorization in Laravel 5.4 with Spatie Laravel-Permission
May 16, 2017 @ 11:28:09

On the Scotch.io site a new tutorial has been posted showing you how to use the Laravel-permission package (from Spatie) to more easily handle permission setup and validation in a Laravel application.

When building an application, we often need to set up an access control list (ACL). An ACL specifies the level of permission granted to a user of an application. For example a user John may have the permission to read and write to a resource while another user Smith may have the permission only to read the resource.

In this tutorial, I will teach you how to add access control to a Laravel app using Laravel-permission package. For this tutorial we will build a simple blog application where users can be assigned different levels of permission.

The tutorial then walks though the installation of the package and some of the new tables it adds to the database when you run the included migrations. It then talks about some of the methods that can be used, both on the backend and in Blade templates, to evaluate if the current user has the roles required. Next up is the creation of the controllers to handle the basic CRUD tasks and working with the blog posts and views to set up the permissions and roles. Finally the tutorial shows the code required to evaluate the roles and permissions of the user and an example of middleware that performs a pre-check to see if a user even has access to manage various pieces of the application.

tagged: tutorial spatie permission role package introduction blog acl ui interface

Link: https://scotch.io/tutorials/user-authorization-in-laravel-54-with-spatie-laravel-permission

SitePoint PHP Blog:
PDS Skeleton by Example: A Standard for File and Folder Structure
May 15, 2017 @ 11:56:29

The SitePoint PHP blog has a tutorial posted by Younes Rafie introducing the php-pds/skelecton package definition and how it can be used to provide some structure and consistency across your package development.

Looking at the Packagist registry, we can see that most packages follow a pattern, with some small changes to fit their needs, while others have a weird folder structure that takes time to get your head around.

This problem has been solved in different ways by different people. Some frameworks have their own recommendations on how to structure your classes and assets, while others have a skeleton that you can use as a starting point. In this article, we’re going to explore the php-pds/skeleton and use it to build a small package as a demonstration.

He then uses a Laravel package example to show the build up of the package structure (based on the pds/skeleton definition). He goes through each portion of the skeleton structure talking about what they should contain:

  • config
  • resources
  • source files
  • tests
  • the "public" directory
  • bin/ folder
  • documentation
  • other files like README and LICENSE documents

He also suggests including a guide to contributing to the package and how to use the "validate" command to be sure this and the other items in the structure are in place.

tagged: pds skeleton package definition structure example tutorial

Link: https://www.sitepoint.com/pds-skeleton-by-example-a-standard-for-file-and-folder-structure/

BugSnag:
Packagist and the PHP ecosystem
May 11, 2017 @ 10:49:17

The BugSnag blog has posted a tutorial from a guest author, Graham Campbell, introducing you to Packagist and the PHP ecosystem continuing on from the previous post introducing the Composer tool.

In our last blog post we saw the basics of Composer, but skipped over where it actually finds its packages, and how to publish packages of your own. In this blog post, we will be looking at exactly this, plus some security considerations when using composer in your application.

The post starts off by introducing Packagist and how you can distribute your package there. There's a section that covers Open Source licenses, a few of the different types and how to list licenses of your currently installed packages. Following this the post talks about using branches and aliases to pull in the code you need (not just the latest release). The tutorial wraps up with a look at some of the security concerns around using packages and how to keep on top of new versions with new bugfixes.

tagged: packagist ecosystem introduction package license security

Link: https://blog.bugsnag.com/packagist-and-the-php-ecosystem/