Laravel Personal Data Export

Freek Van der Herten released a Spatie package called Laravel Personal Data Export last week to help you create zip files containing personal data in your Laravel applications:

This package makes it easy to let a user download an export containing all the personal data. Such an export consists of a zip file containing all the user properties and related info.

With privacy concerns rising on social media and other web applications, exporting user data might be something you want to consider. As seen in the package’s readme, you configure the file and data export by defining a selectPersonalData method the user model:

// in your User model

public function selectPersonalData(PersonalDataSelection $personalDataSelection) {
    $personalDataSelection
        ->add('user.json', ['name' => $this->name, 'email' => $this->email])
        ->addFile(storage_path("avatars/{$this->id}.jpg");
        ->addFile('other-user-data.xml', 's3');
}

The Laravel Personal Data Export package provides configuration for how many days the personal data will be available to the user, along with some other customizable options:

return [
    /*
     * The disk where the exports will be stored by default.
     */
    'disk' => 'personal-data-exports',

    /*
     * The amount of days the exports will be available.
     */
    'delete_after_days' => 5,

    /*
     * Determines whether the user should be logged in to be able
     * to access the export.
     */
    'authentication_required' => true,

    /*
     * The mailable which will be sent to the user when the export
     * has been created.
     */
    'mailable' => \Spatie\PersonalDataExport\Mail\PersonalDataExportCreatedMail::class,
];

This package takes care of the boilerplate of all the tasks involved in initiating the data export and then fulfilling it roughly in the following sequence:

First, the package generates the data when you dispatch a CreatePersonalDataExportJob in the application (a queued job by default).

Next, when the job runs, the exported data is zipped and copied to the configured disk. Finally, the user receives a notification email with the URL to the download.

Almost every piece (if not all) of the export process is customizable. You can check out this package on GitHub at spatie/laravel-personal-data-export.

Homestead Fifty Six

Does your company still use PHP 5.6? Homestead Fifty Six is a development environment for PHP 5.6 and 7.0 by Homestead maintainer Joe Ferguson.

Last week Joe announced the project on his blog:

The most recent major release of Homestead dropped support for PHP 5.6 and 7.0. While these PHP versions are end of life and will no longer be receiving updates, some developers still need access to these tools. You can certainly use and old version of Homestead but at some point the base box will just be too far out of date and things will start breaking. The solution to this problem is for me to continue to maintain a PHP 5.6, 7.x version of Homestead as a project I’m calling “ Homestead Fifty Six “. This project will be based directly off Laravel Homestead but will not be 100% compatible.

Homestead Fifty Six initially has two offerings:

  • $10 per month for access to the packages
  • $15/month for access to packages as well as priority support for any help you may need getting the project working.

With the release of PHP 7.3, the PHP team dropped official support for EOL versions, including versions 5.6 and 7.0. Homestead also dropped support for these versions, which makes perfect sense and reduces the maintenance burden of Homestead.

While users are encouraged to update to new stable releases of PHP, sometimes it’s not so cut and dried in reality. Projects like Homestead Fifty Six aim to bridge that gap and provide access to these tools.

You can read Joe’s full announcement for the full details, including links to purchase access to Homestead Fifty Six.

Sublime Text 3.2 Released

For a while, Sublime stable releases went dark for a long, long time. Then out of nowhere Sublime Text 3.0 stable shipped in September 2017, Sublime Text 3.1 in June 2018, and a new product called Sublime Merge released in September 2018.

In the latest release, Sublime Text 3.2 builds off of Sublime Merge adding first-class Git integration, incremental diffing, new theme functionality around diffs, and block caret support.

All the git integration builds off of Sublime Merge’s custom, high-performance Git library giving Sublime Text a super fast Git experience. The most noticeable difference you’ll see is that files and folders in the sidebar will display badges to indicate Git status:

Here’s what block caret support looks like (Rainglow Kiwi theme shown):

The full announcement details and changelog are available in the official Sublime Text 3.2 announcement post. You can also view the 3.2 changelog within the Sublime application via the menu option (I.e., Sublime Text > Changelog… menu option on Mac).


Also, be sure and check out some of our other resources on mastering Sublime Text:

Laravel 5.8.4 Released

The Laravel team released v5.8.4 yesterday with a new collection join method and an HTTP Kernel middleware getter.

First, the new Collect::join() method to join all items from the collection using a string. The final item can use a separate “glue” string as well:

collect(['a', 'b', 'c']))->join(', ')); // returns 'a, b, c'

collect(['a', 'b', 'c']))->join(', ', ' and ')); // returns 'a, b and c'

collect(['a', 'b']))->join(', ', ' and ')); // returns 'a and b'

collect(['a']))->join(', ', ' and ')); // returns 'a'

collect([]))->join(', ', ' and ')); // returns ''

Next, the HTTP Kernel class has a new getRouteMiddleware() method which could come in handy to ensure that a middleware has been registered:

/** @test */
public function it_registers_a_custom_route_middleware()
{
    $middlewares = resolve(\App\Http\Kernel::class)->getRouteMiddleware();

    $this->assertArrayHasKey('custom', $middlewares);
    $this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}

The last new addition is adding Danish-specific characters to the Str class for proper support when the language is da. Here’s the list of characters from the PR:

'da' => [
    ['ø', 'å', 'Æ', 'Ø', 'Å'],
    ['oe', 'aa', 'Ae', 'Oe', 'Aa'],
],

An important fix is for JSON boolean queries ships in v5.8.4. Laravel’s 5.8 un-quoting of JSON values with MySQL broke boolean comparisons. For full details check out PR #27847.

You can see the full list of fixes below, and the whole diff between 5.8.4 and 5.8.3 on GitHub. The full release notes for Laravel 5.7 are available in the GitHub 5.8 changelog:

v5.8.4

Added

  • Added Illuminate\Support\Collection::join() method (#27723)
  • Added Illuminate\Foundation\Http\Kernel::getRouteMiddleware() method (#27852)
  • Added danish specific transliteration to Str class (#27857)

Fixed

  • Fixed JSON boolean queries (#27847)

Laravel Live UK 2019

Laravel Live UK 2019 is coming to London, UK for a two-day conference between June 10 and 11th, 2019 at the Shaw Theatre. Join hundreds of Laravel and PHP enthusiasts for inspirational talks, engaging networking, and amazing learning opportunities.

At the time of writing, the Laravel Live UK speaker list has an excellent lineup already (with more speakers to be announced):

Laravel Live UK is accepting CFPs, looking specifically for “Laravel focused talks, talks that can be directly applied to the Laravel ecosystem, or related technical talks.” You can fill out the CFP form here.

Talk lengths will vary between 25 to 45 minutes per the CFP form: “We’re looking for a variety of talk lengths ranging from 20 – 45 minutes.”

If you want to attend Laravel Live UK 2019, we’d recommend getting on the early bird list today. Visit laravellive.uk to sign up and learn more about the conference and venue.

Follow @LaravelLiveUK on Twitter for future speaker announcements and news related to the conference.

Bagisto E-commerce Platform

Bagisto is an open-source E-commerce platform built on top of Laravel and Vue.js by Webkul.

Bagisto is an E-commerce ecosystem designed for all to build and scale your business. It’s a free and open-source framework which offers you a wide range of functionality and lets you have total control of your store.

Built on top of Laravel, it is coupled with easy product information management and fast time to market a product. The framework is very flexible and easy to use even for non-tech users.

At the time of writing, Bagisto’s main feature list includes:

  • RTL Support
  • Supports multiple channels, locales, and currencies
  • Built-in access control layer
  • Responsive storefront
  • Admin Panel and Dashboard
  • Custom product attributes
  • Support for multiple store themes
  • Multi-store inventory
  • Order management system
  • Customer cart, wishlist, and product reviews

Bagisto features an administration panel with a Dashboard, sales data, a catalog of products you can manage, and customer management:

Besides the features already available, the Bagisto’s roadmap includes:

  • API Support (REST and GraphQL)
  • Progressive web application
  • Mobile application on the Google Play and Apple App Store
  • Dropshipping
  • Docker integration
  • Elasticsearch integration
  • Support for Redis, Varnish, Nginx, and Memcached
  • Percona support
  • Accelerated mobile pages (AMP) integration
  • CI/CD Pipeline management
  • New product types like subscriptions, bookings, and recurring billing.
  • GDPR compliance

To learn more about Bagisto’s features and try a demo, check out bagisto.com. You can get started with the source code by checking out the repo on GitHub at bagisto/bagisto.

Laravel 5.8.3 Released

The Laravel team released Laravel 5.8.3 yesterday adding a countBy() collection method and a few protected methods to Laravel framework classes.

First, the Collection::countBy method which counts the number of items in a collection by a predicate. By default, the method counts each appearance of a given value:

collect([ 1, 2, 2, 2, 3 ])->countBy();
// == collect([ 1 => 1, 2 => 3, 3 => 1 ])

The countBy method also accepts a predicate argument:

collect([
    'alice@gmail.com',
    'bob@yahoo.fr',
    'carlos@gmail.com'
])->countBy(function ($email) {
    return substr(strrchr($email, "@"), 1);
});

// == collect([ 'gmail.com' => 2, 'yahoo.fr' => 1 ])

Next, the EloquentUserProvider user provider class has a new protected modelQuery method. The PR author’s use-case is extending the eloquent-based user provider without implementing the UserProvider interface. For example:

<?php

namespace App\Extensions;

use Illuminate\Auth\EloquentUserProvider;

class MyEloquentAdminProvider extends EloquentUserProvider
{
    protected function modelQuery($model = null)
    {
        return parent::modelQuery($model)->where('role', 'admin');
    }
}

Next, a protected saveSession method was added to the StartSession middleware, allowing applications to extend the middleware saving logic without overriding the entire handle() method.

The saveSession() method also accepts a $request parameter in case you override this method and need access to the request.

The last addition in this release is allowing Model::belongsToMany to accept a non-hardcoded pivot table name using a Model/Pivot class name as a second parameter:

return $this->belongsToMany(Profile::class, CustomerProfile::class);

You can see the full list of fixes below, and the whole diff between 5.8.2 and 5.8.3 on GitHub. The full release notes for Laravel 5.7 are available in the GitHub 5.8 changelog:

v5.8.3

Added

  • Added Collection::countBy (#27770)
  • Added protected EloquentUserProvider::newModelQuery() (#27734, 9bb7685)
  • Added protected StartSession::saveSession() method (#27771, 76c7126)
  • Allow belongsToMany to take Model/Pivot class name as a second parameter (#27774)

Fixed

  • Fixed environment variable parsing (#27706)
  • Fixed guessed policy names when using Gate::forUser (#27708)
  • Fixed via as string in the Notification (#27710)
  • Fixed StartSession middleware (499e4fe)
  • Fixed stack channel’s bug related to the level (#27726, bc884bb)
  • Fixed email validation for not string values (#27735)

Changed

  • Check if MessageBag is empty before checking keys exist in the MessageBag (#27719)

Get Tickets for Tomorrow’s Laracon Online 2019

It’s hard to believe that Laracon Online 2019 is here this Wednesday, March 6th! There’s still time to get tickets! At $25 Laracon Online is the most accessible PHP conference for a worldwide audience.

Join thousands of developers online and enjoy talks from some of the brightest developers the world has to offer—all from the comfort of your own home or office!

Buy Your Ticket Now for $25

Here’s the lineup of Laracon 2019 schedule: (all times are EST)

  • 8:00 AM Mingle in Chat
  • 8:45 AM Opening Remarks
  • 9:00 AM Freek Van der HertenGetting started with event sourcing in Laravel
  • 10:00 AM Jason McCrearyWriting less complex, more readable code
  • 11:00 AM Marcel PociotReal-time applications with Laravel
  • 12:00 AM Break and Mingle in Chat
  • 12:15 PM Wes Bos – TBA
  • 1:15 PM Taylor OtwellExploring Laravel 5.8
  • 2:15 PM Break and Mingle in Chat
  • 2:30 PM Samantha GeitzLaravel, the Blockchain, and You!
  • 3:30 PM Matt StaufferDatabases in space
  • 4:30 PM Break and Mingle in Chat
  • 4:45 PM Steve SchogerPractical solutions to common UI design problems
  • 5:45 PM Adam WathanTailwind CSS by example
  • 6:45 PM Closing Remarks

What if I can’t make it on March 6th?

You should still pick up a ticket because all talks will be recorded and available online for attendees shortly after the conference ends. Those that can’t make the conference but pay for tickets will still get access to the digital swag.

If you can make it during the conference, it’s going to be an excellent time for great speakers, digital swag, and mingling.

As mentioned on Laravel Snippet #7, Taylor Otwell will be demoing features from the newly released Laravel 5.8 and hanging out in the chatrooms.

If you would like to learn more about the conference, visit laracon.net and follow @LaraconOnline on Twitter for news and announcements.

Buy Your Ticket Now for $25

PHPUnit SpeedTrap

PHPUnit Speedtrap is a package by John Kary that reports on slow-running tests in your PHPUnit test suite. This package is inspired by Ruby RSpec’s --profile option that displays feedback about slow tests:

SpeedTrap reports on slow-running PHPUnit tests right in the console.

Many factors affect test execution time. A test not properly isolated from variable latency (database, network, etc.) and even basic load on the test machine will cause test execution times to fluctuate.

From the project’s readme, here’s an example of what you can expect:

I am not super familiar with tapping into PHPUnit, so I enjoyed diving into the package’s source code and learning how PHPUnit listeners work. In a phpunit.xml file you can enable this package with the following XML:

<listeners>
    <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>

A more extensive example includes customizable options for defining the “slowTreshold” and “reportLength”. You can customize what your test suite considers a “slow” test defined in milliseconds:

<listeners>
    <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
        <arguments>
            <array>
                <element key="slowThreshold">
                    <integer>500</integer>
                </element>
                <element key="reportLength">
                    <integer>5</integer>
                </element>
            </array>
        </arguments>
    </listener>
</listeners>

Along with the listener, the package demonstrates using an annotation to override these configuration options on the per-test level:

/**
 * @slowThreshold 5000
 */
public function testLongRunningProcess()
{
    // Code that takes a longer time to execute
}

You can learn more about the PHPUnit Speedtrap package at johnkary/phpunit-speedtrap and also check out these tips on speeding up your PHPUnit tests

Laravel Horizon 3.0 is Released Featuring a New Dark Mode

The Laravel team shipped Horizon 3.0 yesterday, featuring a new dark mode and other improvements. The overhaul of the Horizon UI includes a new “Night Mode” option and tidying up the jobs list and failed job details screen.



As mentioned in the New UI Pull Request, you now also can change Horizon’s base path /horizon.

Next, the horizon artisan command accepts an --environment flag to set the environment from the command line:

php artisan horizon --environment=worker

To get an overview of what Horizon can do for queue management, check out the main Laravel Horizon landing page. If you are new to Horizon, the Laravel documentation is an excellent place to start to learn how to install and configure Horizon for your application. Horizon is an open-source project, so you can also view and contribute to the source code on GitHub at laravel/horizon.

Check out the Release v3.0.0 on GitHub for the complete release notes:

v3.0.0

Added

  • New UI ( #522 )
  • Set the Horizon environment via command option ( #523 )

Changed

  • Require latest symfony/debug version ( 72cc3a7 )
  • Require symfony/process ( f2a214c )
  • Require ext-json ( 5a54d27 )

Fixed

  • Fix deprecated process calls ( #515 )
  • Add missing createPayloadArray arg ( #516 )

Removed

  • Removed support for Laravel 5.5 & 5.6 ( 8a92e09 )