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

Jason McCreary:
SMS admin in 8 lines of code
Sep 21, 2017 @ 09:45:06

In a new post to his site Jason McCreary shows how he integrated SMS for account administration for the Laravel Shift service. It's his method of providing good support for the project from anywhere, even when he's away from his machine.

In the end, all I need is a quick way to run a Shift on the go. Looking back on almost two years of support, I often have the Shift number readily available. Creating the job and adding it to the queue is at most two lines of code. So the steps are not the pain point.

The pain point is connecting to the server. [...] What do I carry around with me all the time? My phone. I’m already reviewing the support emails from my phone. Wouldn’t it be great when I need to run a Shift manually to just reply or send a text.

He then shares the code he used to create the administration interface via SMS through the Nexmo service. He uses the information the Nexmo service sends to hiswebhook via a special number and handles it via a special endpoint on his side. In this case the interface allows him to re-run a "shift" that was previously requested if there was an error. The code is pretty simple, made up of a controller and route for the endpoint and a "FormRequest" class for the message processing.

tagged: sms administration laravel shift example nexmo

Link: https://jason.pureconcepts.net/2017/09/nexmo-sms-admin-laravel/

Zend Framework Blog:
Emitting Responses with Diactoros
Sep 15, 2017 @ 09:14:05

On the Zend Framework blog they've posted a tutorial from project lead Matthew Weier O'Phinney showing how to use the Diactoros package to create response emitters. These emitters are just methods of output related to HTTP handling (like headers, response codes and normal text output).

When writing middleware-based applications, at some point you will need to emit your response.

PSR-7 defines the various interfaces related to HTTP messages, but does not define how they will be used. Diactoros defines several utility classes for these purposes, including a ServerRequestFactory for generating a ServerRequest instance from the PHP SAPI in use, and a set of emitters, for emitting responses back to the client. In this post, we'll detail the purpose of emitters, the emitters shipped with Diactoros, and some strategies for emitting content to your users.

He starts by describing what "emitters" are in the context of PSR-7 applications and shows the code definition of the EmitterInterface, the base of all emitter classes. After covering some of the emitters that Diactoros includes he shows how to create one to emit file information and how you can mix and match them in a emitter "stack" to perform more that one operation on the output.

tagged: diactoros tutorial emitter response output example interface

Link: https://framework.zend.com/blog/2017-09-14-diactoros-emitters.html

Jeff Madsen:
Custom Pivot Table Models, or Choosing the Right Technique in Laravel
Sep 11, 2017 @ 11:17:09

Jeff Madsen has some helpful hints for the Laravel (or just Eloquent) developers out there when it comes to models. In this new post to his Medium site he looks at using custom pivot table models (and choosing the right technique to use them).

Laravel is “opinionated”, but that usually just means that there are a lot of defaults set up that push you toward a certain style. Over the years I have found very few cases where you can’t easily override these; more often than not, it is simply a case of adding another function call when you instantiate something.

As I thought about the way I would normally code around Mark’s problem, and then searched and found the more direct answer from the docs, it occurred to me that this was a perfect example.

He starts with the more "standard" way of working with pivot tables in Laravel (code example include) using the updateExistingPivot method. He talks about the difference between writing the code and designing the code, making it more maintainable and well-architected. He talks about moving the logic into a service class but points out a few issues with that approach as well. Finally, in his last option, he covers the special "Pivot" model included with Eloquent and shows it in use.

tagged: custom pivot table model laravel tutorial example

Link: https://medium.com/@codebyjeff/custom-pivot-table-models-or-choosing-the-right-technique-in-laravel-fe435ce4e27e

Jeff Madsen:
What’s all this “immutable date” stuff, anyway?
Sep 06, 2017 @ 10:18:42

Jeff Madsen has a post on his Medium blog sharing some of his thoughts about immutable DateTime types, what the difference is between mutable and immutable and "why you should care".

I’m going to show you the difference between the two using two popular Php DateTime libraries? - Carbon and Chronos, and then demonstrate the danger of using the mutable one of those.

You have probably used Carbon? - ?it is a wonderful library put together by Brian Nesbitt that takes all the pain out of working with dates. It has got one “short-coming”, if you will?- ?it is built on top of the DateTime object.

He gives an example of why this is a problem with Carbon (mutable) and how it's handled differently in Chronos (immutable). He makes the point that, unless your date values are immutable, you don't have any idea of they've changed elsewhere in the processing. He gives a more real-world example of working with immutable objects with a "user" model class and the "name" properties attached to it.

tagged: immutable date carbon chronos bug example code tutorial

Link: https://medium.com/@codebyjeff/whats-all-this-immutable-date-stuff-anyway-72d4130af8ce

Laravel News:
BotMan 2.0 PHP Chatbot Framework
Sep 01, 2017 @ 09:20:20

On the Laravel News site today there's a new post covering the release of BotMan v2.0, one of the more popular chatbot libraries for PHP.

BotMan is a framework agnostic PHP Chatbot framework designed to simplify the task of developing innovative bots for multiple messaging platforms, including Slack, Telegram, Microsoft Bot Framework, Nexmo, HipChat, Facebook Messenger, WeChat and many more.

BotMan 2.0 was released earlier this week with a bunch of improvements and exciting changes.

As a part of this new release, functionality was abstracted out into separate repositories making it easier to maintain those features without having to change core code. They then include an example of using the the library to create a simple chatbot that replies to a simple "hello" message. They also cover some of the more advanced features including middleware handling and natural language processing support. There's also a tool, BotMan Studio, that's included with the package to help make testing your chatbot script easier. The post wraps up with an example of using this to test the chatbot and a list of some of the other new features in v2.0.

tagged: botman chatbot framework release v2 overview example

Link: https://laravel-news.com/botman-php-chatbot

Laravel News:
Maximize Your Terminal Productivity
Aug 29, 2017 @ 14:01:53

On the Laravel News site they've posted a guide to help you maximize your terminal productivity by sharing a few tips to help you get the most of out the time you spend at the command line.

This week, we just published some great bash aliases from the community, and I wanted to write more about maximizing your terminal productivity. I’ve coached many developers, and the terminal is often the area I see that many great developers (much better than me) could improve and gain some productivity and better tooling.

After talking about his own first steps as a developer and the tools he used, Paul Redmond talks about the set of helpful tools and software he now uses including:

  • the Zsh shell (and Oh My Zsh)
  • updating the CD Path
  • Using path expansion
  • History completion
  • History search and execution
  • Terminal themes

He ends the post with a few other recommendations of resources to check out and quick tips on sharing the results.

tagged: terminal productivity tips zsh plugin example

Link: https://laravel-news.com/maximize-terminal-productivity

Jeff Ochoa:
Understanding Laravel Pipelines
Aug 29, 2017 @ 10:59:36

On his Medium blog Jeff Ochoa has written up a tutorial that want to help you understand pipelines in Laravel, a fluid interface that can be used to pass objects around.

Basically, using laravel pipelines you can pass an object between several classes in a fluid way to perform any type of task and finally return the resulting value once all the “tasks” have been executed.

[...] The most clear example about how pipelines works resides in one of the most used components of the framework itself. I’m talking about middlewares.

He uses a simple middleware as an example, covering how they're just "pipes" in the pipeline of execution. He includes a snippet of code from the Illuminate handling showing its place in the pipeline and gives a more real world example of commenting functionality with a few different pieces of functionality. He shows how this could be refactored into the pipeline handling and what happens at the end of the pipe.

tagged: laravel pipeline introduction tutorial pipe example

Link: https://medium.com/@jeffochoa/understanding-laravel-pipelines-a7191f75c351

Zend Framework Blog:
Specialized Response Implementations in Diactoros
Aug 24, 2017 @ 14:14:38

On the Zend Framework blog today Matthew Weier O'Phinney has written up a post showing how to implement specialized responses in Diactoros, a PHP package that makes it easier to work more directly with the request and response in your application.

When writing PSR-7 middleware, at some point you'll need to return a response.

Maybe you'll be returning an empty response, indicating something along the lines of successful deletion of a resource. Maybe you need to return some HTML, or JSON, or just plain text. Maybe you need to indicate a redirect.

But here's the problem: a generic response typically has a very generic constructor. [...] Fortunately, Diactoros provides a number of convenience implementations to help simplify the most common use cases.

He then spends the rest of the article showing some example responses types and the code to make them work:

  • EmptyResponse
  • RedirectResponse
  • TextResponse
  • HtmlResponse
  • JsonResponse

Each one is included as a part of the Diactoros package. For more information, check out the documentation for the package and accompanying examples.

tagged: tutorial diactoros package response example http zendframework

Link: https://framework.zend.com/blog/2017-08-24-diactoros-responses.html

TutsPlus.com:
Pagination in CodeIgniter: The Complete Guide
Aug 15, 2017 @ 12:07:18

In this new tutorial posted to the TutsPlus.com site author Sajal Soni shares "the complete guide" to handling pagination in a CodeIgniter framework application using built-in tooling included with the framework.

The benefit of using any full-stack web application framework is that you don't have to worry about the common tasks like input handling, form validation and the like, as the framework already provides wrappers for those features. Thus, it allows you to concentrate on the business logic of the application rather than reinventing the wheel over and over again.

Today, we're going to explore an important library in the CodeIgniter framework—the pagination library.

The tutorial walks you through three main things: the basics of the pagination functionality, options you can use to customize it and the configuration options available for the component. Each section comes with code and configuration examples showing how to use the component.

tagged: pagination codeigniter tutorial options configuration example

Link: https://code.tutsplus.com/tutorials/pagination-in-codeigniter-the-complete-guide--cms-29030`

Derick Rethans:
New Date/Time Support in MongoDB
Aug 15, 2017 @ 09:46:11

In a new post to his site Derick Rethans talks about the new DateTime support in MongoDB and includes some PHP examples showing the changes in action.

In the past few months I have been working on adding time zone support to MongoDB's Aggregation Framework. This support brings in the timelib library that is also used in PHP and HHVM to do time zone calculations.

He then splits the rest of the post up into parts for the changes that this integration brings:

  • Time Zone Support for Date Extraction Operators
  • The $dateToParts Operator
  • The $dateFromParts Operator
  • Changes to the $dateToString Operator
  • The $dateFromString Operator
  • Using Date Expressions in $match

The post ends with a few notes about these changes, noting that it's currently only in the development release and "should be considered experimental" and subject to change. He then points out a few issues that will probably require updates to these features.

tagged: datetime support mongodb example tutorial list

Link: https://derickrethans.nl/mongo-date-time.html