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

Tim MacDonald:
Loading Eloquent relationship counts
Nov 12, 2018 @ 09:51:30

Tim MacDonald has a new post to his site sharing methods that the Laravel Eloquent users (either in the framework or outside of it) can use to load in the counts of relationships without having to fetch the entire relationship data set.

It is often useful to show the number of related models a given instance has, but not actually need any specific information about the related models, just how many exist. In this scenario you do not want to load all of the related models into memory to count them, we want our database to do the heavy lifting for us. Laravel offers a number of ways to retrieve relationship counts. 2 have been around for a while, but there is a new kid on the block.

He looks at three methods you can use to get these counts: via the query builder manually, directly on the relationship and, more recently added, from an eloquent collection. He goes through each of these methods, providing a summary of the technique and code examples showing how it's implemented.

tagged: laravel eloquent relationship count tutorial querybuilder collection

Link: https://timacdonald.me/loading-eloquent-relationship-counts/

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

Oh Dear Blog:
How to size & scale your Laravel Queues
Nov 02, 2018 @ 13:17:03

On the "Oh Dear!" service's blog there's a recent post covering the use of queues in a Laravel application and how to size and scale them to most effectively use the resources you have.

Laravel offers a convenient way to create asynchronous background tasks using its queues. We utilize those heavily at Oh Dear! for all our monitoring jobs and in this post we'll share some of our lessons learned and what we consider to be best practices.

The post starts out with an introduction to queues and their handling in Laravel applications, pushing jobs into workers to be executed. While a simple single-worker queue can handle a decent amount of work, problems can arise as the work grows larger. He mentions splitting up the work as a potential solution and defines the differences between "fast" and "slow" jobs to act as a dividing line for the queues. He also makes the suggestion of single-purpose queues based on types and, finally, mixing in the idea of a better user experience through immediate feedback.

tagged: size scale laravel queue division tutorial

Link: https://ohdear.app/blog/how-to-size-scale-your-laravel-queues

CodeWall:
Install Summernote With Laravel Tutorial
Oct 30, 2018 @ 10:33:21

On the CodeWall site they've posted a new tutorial showing you how to integrate the Summernote WYSIWYG editor into your Laravel application for easier content creation. Summernote is one of many potential WYSIWYG editors that will work easily with Laravel.

What You See Is What You Get (WYSIWYG), is mostly used by the developers for describing a software program which they use for checking visibility of the final product. A user friendly interface is required to run WYSIWYG program. While to write descriptive codes, a developer could use WYSIWYG editor which helps them to see the content that will appear as the end result.

[...] Well users of Laravel have good news, it supports multiple WYSIWYG editors. Therefore, if you are a developer and like developing applications with this brilliant framework, you’re in luck. In this article, I will elaborate about the best WYSIWYG editors you can use working with Laravel. With a plethora of WYSIWYG editors available, it’s quite hard to decide which one best suits your needs. Well, you don’t have to worry a bit. I will provide a detailed account on some of the best Laravel WYSIWYG editors in this article. With these editors, you can easily develop your content and codes. I will also highlight the pros and cons of WYSIWYG editors.

They made the choice to go with Summernote and walk you through the integration process including:

  • a listing of some of the prerequisites
  • configuring the database and making migrations for the content
  • building out the routes, models, views, and controllers

They also show how to add the Summernote instance to a view and configure it to your liking.

tagged: summernote tutorial laravel application integration

Link: https://www.codewall.co.uk/install-summernote-with-laravel-tutorial/

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

Michael Dryrynda:
Using Laravel Telescope in specific environments
Oct 29, 2018 @ 09:45:34

Michael Dryrynda has a post to his site sharing a method for using Laravel Telescope in specific environments. Telescope provides enhanced debugging functionality to Laravel applications for introspection into data about requests, jobs, queues and more.

Whilst its primary purpose is as a debugging tool in development, it is also a powerful asset in debugging your production environment. In order to get Telescope, however, I ran in to some stumbling points in my CI environment in GitLab.

To work around this, I set out to conditionally load Telescope. I stumbled upon this comment from Mohamed Said, which suggested loading the TelescopeServiceProvider in one of your application's service providers, but doing so was not enough.

He goes on to talk about the package auto-discover functionality Telescope uses to load its provider and how this, along with the dont-discover configuration option in Composer's extra section can be used to control its loading. He also includes the code needed to register the provider classes but only in the environments other than "build" and "testing".

tagged: laravel telescope environment load provider autodiscover tutorial

Link: https://dyrynda.com.au/blog/using-laravel-telescope-in-specific-environments

Laravel News:
Laravel Telescope Beta Now Available
Oct 24, 2018 @ 12:09:57

On the Laravel News site they have a post about the Laravel Telescope beta that's just been announced. Laravel Telescope is an introspection and debugging tool that integrates with your Laravel application to provide details gathered during execution and issues along the way.

The first beta release of Laravel Telescope is now out and available for everyone. If you are not familiar with Telescope here is the quick overview:

Laravel Telescope is an elegant debug assistant for the Laravel framework. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps and more. Telescope makes a wonderful companion to your local Laravel development environment.

You can get the beta by installing it through Composer.

You install it the same way you'd install any other Laravel package via a composer require for laravel/telescope and run the installation and migration steps using the artisan command. This tool is only for Laravel applications and is tightly integrated with the tool. For more information on Telescope, check out its GitHub repository.

tagged: laravel telescope introspection tool debugging beta announcement

Link: https://laravel-news.com/laravel-telescope-beta

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