Append Artisan Tables with Laravel 6.15.0

Append Artisan Tables with Laravel 6.15.0

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)

Filed in: News / Releases
Laravel News Partners

Laravel Jobs

Senior Full-Stack Developer
Atlanta, GA - (remote) USA ONLY
Curricula
PHP Laravel Developer
London
Investoo
Senior Backend Developer
Australia
Tixel
CTO
Copenhagen
Tjommi
Looking for Senior Full-stack Laravel/React.js Javascript API Developer - Immediate (Full-time)
Remote
ApproveMe // Document Signing

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.