Skip to content

Instantly share code, notes, and snippets.

View richartkeil's full-sized avatar

Richard Keil richartkeil

View GitHub Profile
@richartkeil
richartkeil / NovaServiceProvider.php
Last active October 12, 2018 08:30
Custom Card in Laravel Nova - Service Provider 1
<?php
// ...
public function boot()
{
parent::boot();
// Let Nova know where your compiled assets will be.
Nova::serving(function (ServingNova $event) {
@richartkeil
richartkeil / NovaServiceProvider.php
Last active October 12, 2018 08:31
Custom Card in Laravel Nova - Service Provider 2
<?php
// ...
protected function routes()
{
Nova::routes()
->withAuthenticationRoutes()
->withPasswordResetRoutes()
->register();
@richartkeil
richartkeil / NovaServiceProvider.php
Created October 12, 2018 08:39
Custom Card in Laravel Nova - Service Provider 3
<?php
use App\Nova\Cards\CustomCard;
// ...
protected function cards()
{
return [
new CustomCard,
@richartkeil
richartkeil / Illuminate\Support\Facades\Storage.php
Last active May 31, 2020 19:54
Laravel Storage and Parallel Testing - Storage Facade
<?php
// ...
public static function fake($disk = null, array $config = []) {
$disk = $disk ?: static::$app['config']->get('filesystems.default');
(new Filesystem)->cleanDirectory(
$root = storage_path('framework/testing/disks/'.$disk)
);
@richartkeil
richartkeil / Tests\CreatesFakeStorage.php
Created November 20, 2018 00:00
Laravel Storage and Parallel Testing - CreatesFakeStorage
<?php
namespace Tests;
use Storage;
use Illuminate\Filesystem\Filesystem;
trait CreatesFakeStorage
{
/**
interface CanBroadcast {
send(event: Event, user: User)
trackReads(track: boolean)
}
class EmailBroadcaster implements CanBroadcast {
send(event: Event, user: User) {
emailService.send({ to: user.email, subject: event.name })
}
trackReads(track: boolean) {
interface CanBroadcast {
send(event: Event, user: User)
}
interface CanTrackReads {
trackReads(track: boolean);
}
class EmailBroadcaster implements CanBroadcast, CanTrackReads {
send(event: Event, user: User) {
class EmailBroadcaster {
send(event: Event, user: User) {
const description = `New event ${event.name} occured at ${event.getTimestamp()}`
emailService.send({ to: user.email, subject: event.name, body: description })
}
}
class NotificationHandler {
private mailer: EmailBroadcaster
interface Broadcaster {
send(event: Event, user: User)
}
class EmailBroadcaster implements Broadcaster {
send(event: Event, user: User) {
const description = `New event ${event.name} occured at ${event.getTimestamp()}`
emailService.send({ to: user.email, subject: event.name, body: description })
}
}
const processUser = functions.firestore
.document("accounts/{accountId}/users/{userId}")
.onCreate(async (snapshot, context) => {
await processTheUser(snapshot);
const event = new UserProcessed(snapshot);
await new Account(context.params.accountId).addEvent(event);
})