DEV Community

Freek Van der Herten
Freek Van der Herten

Posted on • Originally published at freek.dev on

★ The open source department at Spatie is doing overtime

Bad title because we don't do overtime at Spatie, but our team has been very busy putting out new open source stuff. In the past weeks our team has released three new packages. In this post I'd like to quickly introduce them too you.

sheets

First up is spatie/sheets, created by Sebastian. This package helps you in storing and retrieving content that is saved in plain text files. This is great if you have a blog or site that uses markdown files instead of a database to store content. Seb is already using this for his personal site and we're planning on using it on our guidelines site soon.

typed

Next we have the spatie/typed package made by Brent. He's fond of type systems and strictness. PHP's type system has a lot of room for improvement. Probably these improvements should be done in the core, but a lot can be done in userland as well. That's why Brent created the spatie/typed package that gives you stuff like typed lists, generics, tuples, structs on much more.

laravel-view-components

Seb released another package, called spatie/laravel-view-components. It's based on the Introducing View Components in Laravel, an alternative to View Composers post by Jeff Ochoa. It lets you build component classes that can be easily rendered in a Blade view. Here's a quick example taken from the readme:

namespace App\Http\ViewComponents;

use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Auth\Guard;
use Spatie\Menu\Laravel\Menu;

class MainMenuComponent implements Htmlable
{
    /** @var \Illuminate\Contracts\Auth\Guard */
    private $guard;

    /** @var string */
    private $class;

    public function __construct(Guard $guard, string $class = null)
    {
        $this->guard = $guard;
        $this->class = $class;
    }

    public function toHtml(): string
    {
        $menu = Menu::new()
            ->addClass($this->class)
            ->url('/', 'Home')
            ->url('/projects', 'Projects');

        if ($this->guard->check()) {
            $menu->url('/admin', 'Adminland');
        }

        return $menu;
    }
}

@render('mainMenuComponent', ['class' => 'background-green'])

We're using this now in a client project and it's really a beautiful way to work.

laravel-event-projector

Finally I'm busy creating a bigger package that aims to be the easiest way to get started with Event Sourcing in a Laravel application. It's not quite ready for prime time yet, but as usual I'm building it in the open. You can already read some documentation to learn how to work with the package. You'll find the source code in this repo on GitHub. I welcome any questions and suggestions on how to make this package better on the issue tracker of that repo. My aim is to release it somewhere in June.

There's still more in the pipeline. To stay current with our team is doing in the open source space follow our members on Twitter. Here's a handy twitter list to follow them all.

Top comments (0)