Append Artisan Tables with Laravel 6.15.0

Published on by

Append Artisan Tables with Laravel 6.15.0 image

The Laravel team released v6.15.0 this week with support for appending tables in artisan commands, a validated authorization event, and a handler method you can override to customize HTTP exception views:

Validated Auth Event

A new validated auth even fires after the user is retrieved from the user provider and validated but before the Login event. Here’s the test verifying that Validated event was dispatched during an auth attempt:

use Illuminate\Auth\Events\Validated;
 
Event::assertDispatched(Validated::class, function ($event) {
$this->assertSame('web', $event->guard);
$this->assertEquals(1, $event->user->id);
 
return true;
});

Blueprint Supports Grammar Macros

Hafez Divandari contributed the ability for Blueprint to support Grammar macros when building raw SQL statements in the toSql() method. Grammar macros enable you to customize existing grammars.

I don’t have a good example, but here’s the updated condition in Blueprint::toSql() that will consider macros from grammar:

if (method_exists($grammar, $method) || $grammar::hasMacro($method)) {
if (!is_null($sql = $grammar->$method($this, $command, $connection))) {
$statements = array_merge($statements, (array) $sql);
}
}

Custom Exception Views

Maarten Buis contributed a “getHttpExceptionView()” method to the base exceptions Handler class. If you need some custom logic around getting the view used to render exceptions, you can override this method in the application Handler child class.

Here’s the framework’s handler implementation:

/**
* Get the view used to render HTTP exceptions.
*
* @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e
* @return string
*/
protected function getHttpExceptionView(HttpExceptionInterface $e)
{
return "errors::{$e->getStatusCode()}";
}

Append Rows to an Artisan Table

You can append rows to tables in artisan commands using the appendRow method:

public function handle()
{
$table = $this->table(
['Column', 'Another column'],
[]
);
 
$table->appendRow(['Value', 'Another Value']);
$table->appendRow(['Value', 'Another Value']);
}

You can see the full list of new features and updates below and the whole diff between 6.14.0 and 6.15.0 on GitHub. The full release notes for Laravel 6.0 are available in the GitHub v6 changelog:

v6.15.0

Added

  • Added Illuminate\Auth\Events\Validated event (#31357, 7ddac28)
  • Make Blueprint support Grammar’s macro (#31365)
  • Added Macroable trait to Illuminate\Console\Scheduling\Schedule class (#31354)
  • Added support dispatchAfterResponse in BusFake (#31418, e59597f)
  • Added Illuminate\Foundation\Exceptions\Handler::getHttpExceptionView() (#31420)
  • Allowed appending of rows to Artisan tables (#31426)

Fixed

  • Fixed locks for sqlsrv queue (5868066)
  • Fixed Illuminate\Events\Dispatcher::hasListeners() (#31403, c80302e)
  • Fixed testing with unencrypted cookies (#31390)

Changed

  • Allowed multiple paths to be passed to migrate fresh and migrate refresh commands (#31381)
  • Split Console InteractsWithIO to external trait (#31376)
  • Added sms link as valid URL in UrlGenerator::isValid() method (#31382)
  • Upgrade CommonMark and use the bundled table extension (#31411)
  • Ensure Application::$terminatingCallbacks are reset on Application::flush() (#31413)
  • Remove serializer option in PhpRedisConnector::createClient() (#31417)
Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes.

Visit Larafast: Laravel SaaS Starter Kit
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with VILT and TALL stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Anonymous Event Broadcasting in Laravel 11.5 image

Anonymous Event Broadcasting in Laravel 11.5

Read article
Microsoft Clarity Integration for Laravel image

Microsoft Clarity Integration for Laravel

Read article
Apply Dynamic Filters to Eloquent Models with the Filterable Package image

Apply Dynamic Filters to Eloquent Models with the Filterable Package

Read article
Property Hooks Get Closer to Becoming a Reality in PHP 8.4 image

Property Hooks Get Closer to Becoming a Reality in PHP 8.4

Read article
Asserting Exceptions in Laravel Tests image

Asserting Exceptions in Laravel Tests

Read article
Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4 image

Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4

Read article