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

Adelf's Blog:
Are you sure you need entrust or laravel-permission to implement your authorization?
Nov 07, 2018 @ 09:33:19

In a post to his site Adelf aims to help you answer the question of the use of either the Entrust or Laravel-permission packages in your Laravel application to handle your authorization.

"Hmmm, I need some basic authorization, like admin role for admin panel and maybe some editor/moderator role... Let's google it. Wow! Laravel already has packages for that! zizaco/entrust, spatie/laravel-permission and others! Let's choose one!"

That's how it usually happens. Then package's migration will add about 5 tables to store roles, permissions and their relations. [...] It only looks simple: just install package, run ready migration and go on. From long-term point of view for 90% projects it's not the best choice.

He starts with an example of a common situation for most web developers: the inclusion of the package, the database changes that come with it and the management of keeping the permissions in sync. He makes the suggestion that maybe this seemingly "simple" way may not be the best and that, in most cases, they're overkill for what an application needs. He shows how to slim down this functionality using Laravel's own gates/policies and boil it down to just the checks that need to be made without the package overhead.

tagged: tutorial laravel permission entrust package requirement simple

Link: https://adelf.pro/2018/authorization-packages

Laravel News:
Building a Laravel Translation Package – Wrangling Translations
Nov 05, 2018 @ 11:53:20

On the Laravel News site they've continued their "Building a Laravel Translation Package" series of tutorials with the latest article covering the "wrangling" of the translations themselves.

As we’ve discussed earlier in the series, out of the box, Laravel translations are stored in language files. These can be either PHP array-style syntax or straight up JSON files.

[...] The plan for the package is, much like many features of Laravel, to expose multiple drivers to power the translation management. The first driver will utilize Laravel’s existing file-based translations with plans to later add a database driver.

[...] The file driver needs to interrogate the filesystem in order to return the data in the required format. This involves a lot of filtering, mapping and iterating, so we will lean quite heavily on Laravel’s collections.

The tutorial is then divided up into a few different parts, each for a chunk of the package functionality around translation management:

  • listing languages
  • adding languages
  • listing translations
  • adding/updating translations

Each item in the list comes with a summary of the feature and a few lines of code showing how to implement it.

tagged: translations laravel package series management tutorial

Link: https://laravel-news.com/wrangling-translations

Freek Van der Herten:
Making Nova fields translatable
Nov 05, 2018 @ 09:53:23

Freek Van der Herten has a new post to his site sharing a method he's worked up to make Nova fields translatable as a part of the functionality provided by the Laravel Nova too.

Laravel Nova is cool package to quickly create admin interfaces in a Laravel app. Unfortunately there's no support for multiple locales out of the box. A while ago we published a package called nova-translatable that makes any of the built in field types translatable.

He shows how to use the package they've developed to store the translations in a JSON column in the related model's database table. He includes screenshots of the interface and code snippets along the way to help you easily integrate this feature into your resulting administration page(s).

tagged: laravel nova laravelnova field translate tutorial package

Link: https://murze.be/making-nova-fields-translatable

Laravel News:
Building a Laravel Translation Package – Scaffolding
Oct 29, 2018 @ 11:27:42

The Laravel News site has continued their series of posts covering the creation of a Laravel translation package with part two of the series. In this latest article they build on part one's introduction and start to build out some of the scaffolding for the package.

In Part 1, we introduced that this series would cover the process of building and maintaining an open-source package for Laravel. Check it out for an overview of what we’ll create in this series. Next, we are going to get to work on scaffolding a new Laravel package.

The post then walks you though the basics of scaffolding a package including:

  • repository setup
  • Composer configuration creation
  • defining the package structure
  • the creation of a service provider
  • testing

Examples of the Composer configuration are included but the remainder of the points will be developed over the next several parts of the series.

tagged: laravel tutorial package translation scaffolding part2 series

Link: https://laravel-news.com/scaffolding-a-package

Laravel News:
Building and Maintaining a Laravel Translation Package
Oct 22, 2018 @ 11:28:08

The Laravel News site has kicked off a series of posts sharing some of the experiences from Joe Dixon about the creation and maintenance of a Laravel translation package.

In this multi-part series, we’ll be documenting the process of building and maintaining an open-source package for Laravel. We will cover everything from bootstrapping the package to dealing with your first issues and pull requests and as much as we possibly can in between.

In this first part of the series he goes over some of the basics:

  • why they're building the tool
  • what they're planning on creating
  • how they're expecting it to be used

There's a bit of background about the tools they're planning on using and pseudo-code of how it will work.

tagged: laravel translation package series part1

Link: https://laravel-news.com/building-laravel-translation-package

Laravel News Podcast:
Episode 69 - Laravel 5.7, ZSH, and Nova packages
Oct 09, 2018 @ 09:39:08

The Laravel News podcast, hosted by Jacob Bennett and Michael Dyrynda has posted a recent episode: Episode #69 - Laravel 5.7, ZSH, and Nova packages

Jake and Michael discuss all the latest Laravel releases, tutorials, and happenings in the community.

Topics mentioned in this latest show include:

You can listen to this latest show either using the in-page audio player or by downloading the mp3 directly. If you enjoy the show, be sure subscribe to their feed to keep up with new shows as they're released.

tagged: laravelnews podcast ep69 laravel57 zsh nova package

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

Freek Van der Herten:
Use custom html components in your Blade views
Oct 02, 2018 @ 09:14:14

Freek Van der Herten has a post for the Laravel users out there showing how to use custom HTML components in your Blade views making use of this package.

Today we launched our newest package called BladeX. In short this package provides you with an easy html like way to render custom html components in your Blade views. In this blogpost I'd like to introduce the package to you.

He starts by describing an example application where reusable components could be helpful (things like alert messages, form components and layout parts). He then shows how to create a component for an alert message that can be used via the @component functionality in Blade as a sort of "include and use" call. He shows how to pass in variables, use slots, and prefix components. He wraps up the post going "under the hood" and showing how it works via a service provider and how they made the package (and why).

tagged: blade view laravel tutorial package html component

Link: https://murze.be/use-custom-html-components-in-your-blade-views

TheCodingMachine.io:
Safe PHP - Throwing Exceptions Instead of Returning False
Sep 27, 2018 @ 11:47:44

On TheCodingMachine.io there's a tutorial posted by David Négrier covering an interesting idea when handling "falseness" in your PHP application - throwing exceptions rather than returning false. In this case, he introduces the "safe" library to help make this easier.

At TheCodingMachine, we are huge fans of PHPStan. PHPStan is an open-source static analysis tool for your PHP code. [...] PHPStan has this notion of "levels" and we strive on each of our projects to reach "level 7" (the maximum level). But PHPStan is constantly improving, and reaching level 7 becomes harder and harder as the tool becomes more strict (this is a good thing!).

The post includes an example of this increasing strictness, showing how a more recent check looks at a file_get_contents call and ensures all possible return values are evaluated (it returns false when it errors). They refactor the code example to more correctly check for this, but losing some of the "expressiveness". The tutorial then spends some time talking about the history of PHP and why things return false rather than throw exceptions on error. It covers some of the basics of how the safe library works and a PHPStan extension that can help find places that need to be wrapped by "safe" to throw exceptions when false is returned.

tagged: safephp library exception false return value tutorial package

Link: https://thecodingmachine.io/introducing-safe-php

StarTutorial.com:
Modern PHP Developer - Composer
Sep 17, 2018 @ 12:07:01

On the StarTutorial.com site they've posted a tutorial for those that might be newer to the PHP language and ecosystem around it covering the use of Composer. In this latest tutorial they cover some of the basics of using this package manager to pull in and use dependencies in your PHP application.

In general, a block of code forms a method, a group of methods forms a class and a set of classes form a package. A reusable package can be dropped into any project and be used without any need to add functionality to it. A package exposes APIs for clients to achieve a single goal. Packages help our applications achieve DRY (Don't Repeat Yourself), a principle of software development, which reduces repetition of information of all kinds.

[...] In most cases, packages have dependencies. [...] We do need a package manager, a package manager that can solve all of these dependency headaches for us.

The tutorial then goes on to compare two of the main package managers in PHP: Composer and PEAR. It then walks through the installation of Composer and how to use it to pull in a package (in this case the "Faker" package for generating fake user data). It also explains the different commands and configuration files used in working with Composer.

tagged: tutorial introduction composer package manager development

Link: https://www.startutorial.com/articles/view/modern-php-developer-composer

Terry Chay:
Which has better packages, Python or PHP?
Sep 13, 2018 @ 10:27:50

Terry Chay has an interesting post on his site that wonders which language has better packages - PHP or Python?

It depends on the target utility. In the Python world, the most common package installer is pip; the PHP world didn’t settle on a dominant format/installation for packages until composer, and that was relatively recently (last 4 years).

[...] So which has better packages? The answer is it depends on the domain. In nearly any language you can find an adequate package for any of your needs, but overall you will find the packages are higher quality, more up-to-date, and sometimes just better overall in the domain the language seems to target well.

He starts off by talking some about PHP and Python's origins - PHP as a web-focused language and Python as more general purpose - and how this influenced their package implementations. He then shares his opinions on which kind of packages are a more natural fit for which languages:

  • for data science/AI/ML applications, Python
  • for DevOps, relying on other tools (Puppet/Chef/Ansible/etc) is better
  • For server-side web-based packages, I feel PHP and Composer [are the solution]

He also includes some thoughts about other languages - Ruby, Javascript, Go - and their own package managers.

tagged: package manager python comparison opinion usage

Link: http://terrychay.com/article/which-has-better-packages-python-or-php.shtml