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.

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

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant 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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

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

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article