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

Laravel News:
Five Useful Laravel Blade Directives
May 23, 2018 @ 09:29:53

On the Laravel News site they've shared a list of five useful Blade directives that you may not have known about. Blade is the templating language included with the Laravel framework by default.

We’re going to look at five Laravel Blade directives you can use to simplify your templates, and learn about some convenient directives that make solving specific problems a cinch! If you’re new to the framework, these tips will help you discover the excellent features of Blade, Laravel’s templating engine.

The five on their list provide functionality to:

  1. Check if the user is authenticated
  2. Check if the user is a guest
  3. Include the first view if it exists or includes the second if it doesn’t
  4. Include a view based on a condition
  5. Include a view if it exists

Each one comes with example code showing it in use and a bit of explanation behind its use.

tagged: laravel directive blade template top5 list

Link: https://laravel-news.com/five-useful-laravel-blade-directives

Zend Framework Blog:
Zend Framework/Homestead Integration
May 18, 2018 @ 12:48:26

On the Zend Framework blog, project lead Matthew Weier O'Phinney has posted a tutorial showing you how to set up a Homestead instance for Zend Framework thanks to a few helpful submissions from the ZF project.

Last year, we tagged: zendframework homestead integration tutorial laravel apigility zendexpressive

Link: https://framework.zend.com/blog/2018-05-16-homestead.html

Laravel News:
Developing Laravel Packages with Local Composer Dependencies
May 18, 2018 @ 10:10:53

On the Laravel News site they've posted a tutorial sharing some helpful hints for the Laravel users out there about developing package locally without having to release it and wait to pull the latest version back down.

Developing Composer packages locally through a local file symlink speeds up development immensely when you want to create Laravel packages and try them out on a real application. I was reading about a tagged: laravel package local development tutorial composer

Link: https://laravel-news.com/developing-laravel-packages-with-local-composer-dependencies

Laravel News:
Introducing View Components in Laravel, an alternative to View Composers
May 16, 2018 @ 10:55:56

On the Laravel News site there's a new post covering a refactoring of view handling that's possible with recent versions of the framework: using view components instead of view composers..

In software development, one of the “best practices” is to create reusable code that can be implemented in different parts of your application if needed. [...] View composers allow you to move the logic outside your controller and pass the data to the specified set of views. [Using view components instead of composers lets you] reuse complex components using dynamic data on any view within your application.

To help illustrate the difference they set up a scenario of a blog with a "highlights" sidebar based on data from an API response. With view composers you could extract this logic out of the controllers and add it more automatically to the view itself. They point out that this can work for a majority of the situations there's another method that is even more flexible: a reusable component implemented directly on the view. He provides the complete code showing an examples of this components, including a custom Blade directive.

tagged: laravel tutorial view composer component refactor

Link: https://laravel-news.com/introducing-view-components-on-laravel-an-alternative-to-view-composers

Joe Ferguson:
Getting Lucky With Crystal in Homestead
May 16, 2018 @ 09:12:27

Laravel users are no doubt familiar with the Homestead VM project that makes it quick and easy to get new sites up and running. In this new post to his site, project maintainer Joe Ferguson covers some changes made to run something besides a PHP framework: a Crystal project.

A few days ago a random internet stranger (Rid) showed up in the Larachat Slack #homestead-dev room. This is about the best real time chat support for Homestead. Rid proceeds to ask about building something like Homestead for the framework he was working on called Lucky for the [Crystal programming language](https://crystal-lang.org/). After we chatted about Vagrant and Docker I mentioned that it wouldn’t be too difficult to get supported in Homestead. Rid shared some helpful URLs and I was off to the races.

Joe mentions that the next Homestead box will come configured to support this out of the box but also provides instructions if you'd like to set it up before that. The Cyrstal language is inspired by Ruby and is designed to be as "fast as C".

tagged: crystal laravel homestead language framework lucky tutorial

Link: https://www.joeferguson.me/getting-lucky-with-crystal-in-homestead/

Junior Grossi:
Querying and Eager Loading complex relations in Laravel
May 15, 2018 @ 10:15:05

Junior Grossi has a tutorial posted to his site for the Laravel (well, Eloquent) users out there showing how to work with querying and eager loading complex relationships to access the data from your database.

Laravel is a PHP framework that uses Eloquent, a powerful and amazing ORM that allows you to do complex SQL queries in a very easy way. But sometimes you need more, and here I’m gonna give you an interesting tip that can bring you a lot of flexibility.

He sets up the situation where, as an application grows its needs for interaction with the data evolves and becomes more complex. Laravel (Eloquent) comes equipped with some tools that can help with this. To illustrate, he outlines a basic "blog" application with Post and Comment types and their relations. While it's simple to get the comments for a post, querying them can get a little more complex. He provides some examples using whereHas/orWhereHas but points out an issue with the results (all comments are returned, not just the ones matching the queried posts).

The solution he proposes is to eager load them instead. His example code still uses the whereHas but adds the comments to a temporary variable which is then filtered via a with on the query.

tagged: laravel complex relationship query filter tutorial

Link: https://blog.jgrossi.com/2018/querying-and-eager-loading-complex-relations-in-laravel/

TutsPlus.com:
How Laravel Broadcasting Works
May 07, 2018 @ 11:41:41

The TutsPlus.com site has a new tutorial posted for the Laravel users out there ]introducing you to the framework's broadcast functionality](https://code.tutsplus.com/tutorials/how-laravel-broadcasting-works--cms-30500). Broadcasting in Laravel provides a simple interface to sending notification (such as emails or even real-time push messages) via a standardized interface.

Today, we are going to explore the concept of broadcasting in the Laravel web framework. It allows you to send notifications to the client side when something happens on the server side. In this article, we are going to use the third-party Pusher library to send notifications to the client side.

If you have ever wanted to send notifications from the server to the client when something happens on a server in Laravel, you're looking for the broadcasting feature.

The article walks through the scenario first and covers the basic flow of websockets and how they'd be used for messaging. From there they start in on the code, looking at the broadcast configuration and walking you through the setup of a Pusher account and the installation of the SDK. They help you configure the Laravel application for Pusher and install the Laravel Echo library for handling the messaging on the frontend. The tutorial goes through the code to create a "messages" table and hook in a "broadcast on" event. This is followed by the frontend setup including the Javascript to create the Pusher instance.

tagged: laravel broadcast pusher tutorial event websocket

Link: https://code.tutsplus.com/tutorials/how-laravel-broadcasting-works--cms-30500

Laravel News:
Speed Up Laravel on Top of Swoole
May 07, 2018 @ 10:47:09

On the Laravel News site there's a tutorial posted showing you how to use the Swole extension to speed up your Laravel-based application. Swole is a PHP extension written in C that provides missing asynchronous functionality to the language.

Swoole is a production-grade async programming framework for PHP. It is a PHP extension written in pure C language, which enables PHP developers to write high-performance, scalable, concurrent TCP, UDP, Unix socket, HTTP, WebSocket services in PHP without too much knowledge of the non-blocking I/O programming and low-level Linux kernel. You can think of Swoole as something like NodeJS but for PHP, with higher performance.

The post covers the "why?" question of using Swoole with Laravel, explaining how the traditional PHP request flow works. Swoole provides a way to reduce come of this processing overhead and increase performance. They then help you integrate Swoole and Laravel using a custom package (swooletw/laravel-swoole), installing both the package and using PECL to install the Swoole extension. Once the extension is enabled and the service provider is added, all it takes is an artisan command to start the web server up.

The post finishes with some quick benchmarks using wrk comparing it against a typical Nginx setup with PHP-FPM. Not surprisingly, Swoole outperforms the other setup well.

tagged: laravel swoole extension performance tutorial package install

Link: https://laravel-news.com/laravel-swoole

Laravel News:
Laracasts: What’s New in Laravel 5.6
May 02, 2018 @ 11:54:59

On the Laravel News site they've posted information about a series of videos on the Laracasts site covering what's new in Laravel 5.6.

Laravel 5.6 has been for a few weeks now and it includes a few nice new features like Broadcast Channel Classes, Collision Reporting, Improved Logging, and more.

In order to get you up to speed on all these new features, Laracasts has started a new free series, “What’s new in Laravel 5.6” that will go through each major feature of this release.

The series includes videos covering how they upgraded the Laracasts' codebase to 5.6, collision reporting, logging improvements and dynamic rate limiting. More videos will be added to the series as it goes along. You can check out the current listing of videos on the Laracasts site.

tagged: laravel release feature laravel56 video laracast series

Link: https://laravel-news.com/laracasts-whats-new-in-laravel-5-6

Learnk8s.io Blog:
How to deploy Laravel to Kubernetes
Apr 30, 2018 @ 13:10:24

The Learnk8x.io blog has a tutorial they've posted showing you how to deploy a Laravel application to Kubernetes. Kubernetes is a system created to make it simpler to deploy containerized applications in a clustered context.

Vagrant is very good with setting up a local environment similar to a remote server. However, in production, you will most likely require more than just one web host and one database. You’ll probably have separate services for several requirements. You also need to have mechanisms in place to ensure that the application is always online and that the servers can efficiently balance the load.

In this article, I’ll explain how to deal with the simple requirement of running a Laravel application as a local Kubernetes set up.

The article then gets into the "whats" and "whys" of using Kubernetes and an introduction to the Minikube local Kubernetes environment. It runs through some of the prerequisites to getting the deployment set up and provides the Docker configuration to create and link the containers together. With that defined it provides the commands to get the environment up and running and the application deployed. The final part of the tutorial covers the scaling of the system and allowing ingress to the application through a certain URL.

tagged: kubernetes tutorial deploy laravel application docker container

Link: https://learnk8s.io/blog/deploying-laravel-to-kubernetes