Terminal: An Elegant Wrapper around the Symfony Process Component

Terminal is a neat PHP package by Titas Gailius that provides a “wrapper around Symfony’s Process component.” It has a fluent interface, which makes running terminal commands a breeze:

Terminal::in(storage_path('sites/123'))
    ->timeout(120)
    ->retries(3)
    ->run('wp cli update');

In the most simple form, a command might look like the following—which removes a lot of boilerplate and lower-level details of the wonderful Symfony Process component:

$response = Terminal::run('rm -rf vendor');

Here are some things you can do with the response from the run command:

$response->code() : int;
$response->ok() : bool;
$response->successful() : bool;

$response->lines() : array;
$response->output() : string;
(string) $response: string;

// Terminal captures exceptions that you can throw
$response->throw();

// You can access the symfony process
$response->process();

// All calls not found on the Response are passed to Symfony process
// \Symfony\Component\Process\Process::isRunning()
$response->isRunning();

Here are a few more neat examples from the readme:

// Passing data to the command
Terminal::with([
    'firstname' => 'John',
    'lastname' => 'Doe',
])->run('echo Hello, {{ $firstname}} {{ $lastname }}');

// Retries and duration between each retry
Terminal::retries(3, 100)->run('rm -rf vendor');

// Environment variables
Terminal::withEnvironmentVariables([
    'APP_ENV' => 'testing',
])->run('rm -rf $DIRECTORY');

You can learn more about this package, get full installation instructions, and view the source code on GitHub at TitasGailius/terminal.

Laravel 7.3 Released

The Laravel team released v7.3.0 yesterday with the ability to use ^4.0 versions of ramsey/uuid. Since the release of Laravel 7.2, a few patch releases are available that we’ll briefly cover:

Ability to use Ramsey UUID V4

Laravel 7.3 adds the possibility to use ^4.0 of ramsey/uuid, but still supports v3.7 as well. The composer dependency is now ^3.7|^4.0.

Component Fixes

Laravel 7.2.2 fixes a few blade component issues. Notably, the make:component command now supports subdirectories:

php artisan make:component Navigation/Item

# previously creates the following:
  # View/Components/Navigation/Item.php
  # views/components/item.blade.php

# Now creates them as expected:
  # View/Components/Navigation/Item.php
  # views/components/navigation/item.blade.php

Fix Route Naming Issue

Laravel 7 introduced route caching speed improvements, but with that have been a few issues with apps in-the-wild. Laravel 7.2.1 fixed a route naming issue with cache; you should upgrade to the latest 7.x release to get the newest routing fixes.

It’s important to note that you should ensure the uniqueness of route names, as routes with duplicate names can “cause unexpected behavior in multiple areas of the framework.”

Release Notes

The remainder of the updates since v7.2.0 are changes and fixes, which are listed in full below. You can see the full list of new features and updates below and the whole diff between 7.2.0 and 7.3.0 on GitHub. The full release notes for Laravel 7.x are available in the latest v7 changelog:

v7.3.0

Added

  • Added possibility to use ^4.0 versions of ramsey/uuid (#32086)

Fixed

  • Corrected suggested dependencies (#32072, c01a70e)
  • Avoid deadlock in test when sharing process group (#32067)

v7.2.2

Fixed

  • Fixed empty data for blade components (#32032)
  • Fixed subdirectories when making components by make:component (#32030)
  • Fixed serialization of models when sending notifications (#32051)
  • Fixed route trailing slash in cached routes matcher (#32048)

Changed

  • Throw exception for non existing component alias (#32036)
  • Don’t overwrite published stub files by default in stub:publish command (#32038)

v7.2.1

Fixed

  • Enabling Windows absolute cache paths normalizing (#31985, adfcb59)
  • Fixed blade newlines (#32026)
  • Fixed exception rendering in debug mode (#32027)
  • Fixed route naming issue (#32028)

Keep Track of Model Inventory with Laravel Stock

Laravel Stock is a package by Appstract for keeping track of inventory counts on models:

Keep stock for Eloquent models. This package will track stock mutations for your models. You can increase, decrease, clear, and set stock. It’s also possible to check if a model is in stock (on a certain date/time).

For example, let’s say you have a Book model with which you need to keep track of stock:

use Appstract\Stock\HasStock;

class Book extends Model
{
    use HasStock;
}

When a customer places an order for a book, you can change the stock counts:

$book->increaseStock(10);
$book->decreaseStock(10);

// Change stock positively or negatively with one method
$book->mutateStock(10);
$book->mutateStock(-10);

Next, in your UI you could check to see if a product is in stock:

$book->inStock();
// See if you have at least 10 of the same book in stock
$book->inStock(10);

Finally, you can clear stock out:

$book->clearStock();

// Clear stock and then set a new value
$book->clearStock(10);

You can learn more about this package, get full installation instructions, and view the source code on GitHub at appstract/laravel-stock.

How We Run Laracon Online

Ever wondered what all goes into running an online conference? Or want to see the behind scenes on how we do Laracon Online each year?

Ian Landsman has a new post on his site on how to run a successful online conference:

A few weeks ago we completed our fourth installment of Laracon Online. An annual fully online conference for the Laravel PHP framework and related technologies.

Each year Laracon Online has over 4,000 paid attendees from over 100 countries.

With the rise of COVID-19 and the cancellation of so many significant events it seemed like the right time to write up how we pull off Laracon Online and how you can do the same.

Read the full post for all the details and what all is involved.

***
Featured photo by Andreas Dress from Unsplash

Laravel Airlock Renamed to Sanctum

Last week the Laravel blog announced that Laravel Airlock needed to change “due to a trademark dispute regarding the name ‘Airlock.'”

The new name is Laravel Sanctum.

You may even be coming here after seeing an airlock package abandonment warning when installing v1.x versions:

Below you can find a few other details on updating your code if you depend on laravel/airlock.

TLDR

You need to find/replace anywhere in your code you find Airlock and airlock to Sanctum and sanctum, respectively.

Steps to Update

Everything feature-wise remains the same, but you’ll need to make a few changes to start using the new repo and drop the abandoned laravel/airlock package. The diff of the documentation page could be helpful to follow along if you need to update existing projects.

The rough steps to change from Airlock involve the following:

  1. Add the laravel/sanctum composer dependency
  2. Either publish the sanctum vendor config or move the existing config/airlock.php config
  3. Find/replace Airlock for Sanctum and airlock for sanctum
    • If you’re using the middleware for a SPA, change Airlock to Sanctum
    • Update any environment configuration for AIRLOCK_STATEFUL_DOMAINS to SANCTUM_STATEFUL_DOMAINS
  4. Remove config/airlock.php
  5. Remove laravel/airlock from the project’s composer dependencies

Note: be sure to remember to retain any customizations you’ve made to config/airlock.php

Here are the rough commands for all the steps:

# Step 1 - install Sanctum
composer install laravel/sanctum

# Step 2 - Publish the sanctum vendor config
php artisan vendor:publish \
  --provider="Laravel\Sanctum\SanctumServiceProvider"

# Step 3
# Manually find/replace Airlock instances in your code


# Step 4 - if you published config/sanctum.php
rm config/airlock.php

# Step 5
composer remove laravel/airlock

Here’s the example from the documentation for importing the Sanctum middleware, so if you’ve done this already in your project change use Laravel\Airlock\... to reference use Laravel\Sanctum\... instead:

use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;

'api' => [
    EnsureFrontendRequestsAreStateful::class,
    'throttle:60,1',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Learn More

To learn more about using Sanctum, check out the official documenation. The source code is on GitHub at laravel/sanctum.

Laracon US 2020 Cancelled

Today, the team behind Laracon US announced on Twitter they are canceling the event due to COVID-19:

We have postponed Laracon US 2020 and are refunding all orders. We have to refund each order individually so that may take a few days. We will be back soon with news on our next steps, including a possible online event.

Both Laracon EU and Laravel Live have canceled as well. As soon as we get information about these events we will be sure and pass them along.

pdfmatrix.com: fast and reliable HTML 2 PDF conversion SaaS (sponsor)

The online application pdfmatrix.com may be relatively young on the PDF toolkit scene, but it has already pulled FAR ahead of its competitors with a lot of happy clients making it their go-to for HTML/URLs to PDF conversion in the months after its initial release. In case you are wondering, yes – FAR is an acronym. One that stands for Fast, Affordable, Reliable. Having said that, let’s break down all the neat aspects that provide pdfmatrix.com with its competitive edge.

pdfmatrix.com is based on Laravel’s latest version, coupled with smooth and seamless UI and API. As for the app’s HTML/URL to PDF conversion superpowers, they are based on pre-launched Chrome browsers; this speeds up the HTML to PDF conversion process. The browsers are dedicated and isolated for each user and are scaled based on load / requests to unlimited instances. The browsers themselves are isolated and they are being used only by a single user at a time, no user data is saved or shared.

The application’s servers reside at the depths of the DigitalOcean, where speed, security, and scalability are ensured, as the PDF docs generated by users are stored at a secure cloud storage. But the cherry on top through which pdfmatrix.com finds its fine balance between affordability, performance, and efficiency is the tons of customization options that the application enables its users to perform while converting their HTML files or URLs.

What makes pdfmatrix.com unlike any of its competitors is that it allows users to convert an entire website into a single PDF page. What this means is that you can encompass the entirety of a given website’s contents, all within your single-paged PDF doc. Another nice feature to be highlighted is that pdfmatrix.com has the ability to scroll down to the bottom of the page you wish to convert, where it waits for all the resources to load and then scrolls up back again.

In effect, this way the entire webpage is being captured as the application waits for all the images and scripts to be loaded before arranging everything within a single PDF page. The app also allows for grey-scaling the converted HTML/URL through a CSS filter for those of you distracted by too much color, or taking a screenshot of the page for the sake of extra convenience. All this on top of some more standard customization options such as setting margins and content parameters.

This across-the-board customization that pdfmatrix.com offers is available with all of the service’s monthly subscription plans. The only thing that separates the free from the basic, and then the basic from the PRO plan, is the number of API requests included for one month. Still, if you haven’t squeezed your monthly plan to the absolute maximum, fear not. The number of API calls you have not used in any one month are automatically transferred to the following one, so you lose nothing. As for the files that you have created, they are securely stored for free for one month or until deleted by you.

Using pdfmatrix.com in combination with other web-based tools is made easy through its Zapier integration. So, to sum up, and keep it really short and sweet, pdfmatrix.com is a convenient to excellent choice for fellow developers, small to medium businesses and regular dudes, all of you who wish to save on precious time and costly toolkits and spend more on productivity.

See for yourself:
<https://pdfmatrix.com/>

Using Google Sheets with Eloquent

Eloquent Sheets is a package by Ed Grosvenor that lets you work with Google Sheets via Eloquent models:

This package provides an Eloquent model that sits on top of a Google Sheet. In order for it to work, there are two things your sheet needs to have. One is a heading row that holds the name of your columns. This defaults to row 1 (the top row) but it can be any row in the sheet. The other is a primary key column. Eloquent assumes that your primary key column is named id. If it’s not, set it in your model like you would normally.

Going through the readme will get you set up, and once you have a generated model class, it will look something like the following example:

use Grosv\EloquentSheets\SheetModel;

class YourGoogleSheetsModel extends SheetModel
{
    // The id of the spreadsheet
    protected $spreadsheetId = '1HxNqqLtc614UVLoTLEItfvcdcOm3URBEM2Zkr36Z1rE'; 
    // The id of the sheet within the spreadsheet (gid=xxxxx on the URL)
    protected $sheetId = '0';
    // The row containing the names of your columns (eg. id, name, email, phone)
    protected $headerRow = '1';
}

With the Google Sheet model, you can use basic eloquent features; however, the model can only use read and list methods at this time. Update and insert won’t work, but this package does provide a way to read sheet data via Eloquent. Insert and update functionality might be added in the future.

If you’d like to learn more about this package, check it out on GitHub at grosv/eloquent-sheets.

Laravel 7.2 Released

The Laravel team released v7.2.0 this week with HTTP client query string support and a new timeout configuration option for the SMTP mail driver.

Let’s check out the new features real quick:

The expectsConfirmation Test Method

ShawnCZek contributed the expectsConfirmation() method on the PendingCommand class used to test artisan commands:

$this->artisan('foo:bar')
    ->expectsConfirmation('Do you want to continue?', 'no')
    ->assertExitCode(1);

The confirmation assertion uses expectsQuestion under the hood, but asserts the actual value from the test. The same above would originally need to be:

$this->artisan('foo:bar')
    ->expectsConfirmation('Do you want to continue?', true)
    ->assertExitCode(1);

SMTP Mail Driver Timeout

Markus Podar contributed a timeout configuration for the SMTP mail driver. The default is 30 seconds. If you want to tweak the default, add a custom timeout configuration in seconds:

'timeout' => 60, // seconds

HTTP Client Query String Support

Irfaq Syed contributed query string support to the Laravel HTTP Client, meaning you can pass a second argument to Http::get():

Here’s an example of how it works:

Http::get('https://example.com/get');
// URL: https://example.com/get

Http::get('https://example.com/get?abc=123');
// URL: https://example.com/get?abc=123

Http::get('https://example.com/get', ['foo' => 'bar']);
// URL: https://example.com/get?foo=bar

Http::get('https://example.com/get', 'foo=bar');
// URL: https://example.com/get?foo=bar

Note that passing query params to get() overrides any present in the URI, so use one or the other. Overriding the defaults is how Guzzle handles this situation as outlined in Pull Request #31996.

You can see the full list of new features and updates below and the whole diff between 7.1.3 and 7.2.0 on GitHub. The full release notes for Laravel 7.x are available in the latest v7 changelog:

v7.2.0

Added

  • Added Illuminate\Testing\PendingCommand::expectsConfirmation() (#31965)
  • Allowed configuring the timeout for the smtp mail driver (#31973)
  • Added Http client query string support (#31996)

Fixed

  • Added missing ramsey/uuid dependency to Illuminate/Queue/composer.json (#31988)
  • Fixed output of component attributes in View (#31994)

Changed

  • Changed cookie helper signature to match CookieFactory (#31974)
  • Publish the form request stub used by RequestMakeCommand (#31962)
  • Handle prefix update on route level prefix (449c80)
  • Ensure SqsQueue queues are only suffixed once (#31925)
  • Added space after component closing tag for the View (#32005)

GitHub Mobile is Now Available for iOS and Android

GitHub announced that GitHub for mobile is generally available now on the App Store and Google Play Store:

At Universe, we announced GitHub for mobile as a fully-native GitHub experience on iOS and Android. Now, you can stay in touch with your team, triage issues, and even merge code, right from your mobile device, anywhere…Today, both the iOS and Android versions of GitHub for mobile are out of beta and generally available.

With GitHub mobile you can:

  • Review and merge pull requests
  • Push notifications for pull requests and issues
  • Respond to comments on the go

The review and merge experience. Credit: GitHub.blog

The app also incorporates GitHub’s new default web notifications experience, which means you’ll get a consistent experience either at your desk or on the go with the mobile app:


Inbox, notifications, and tasks. Credit: GitHub.blog

For details about the new notifications experience, check out New from Universe 2019 post on the GitHub blog.

For me, using the original mobile interface wasn’t awful, but commenting on pull requests was a bit cumbersome. So far, the native GitHub app has been a much better experience when I need to manage code reviews and issues on the go. The overall experience is better and cohesive with the browser experience.

Check out the full announcement post for further details.