Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Tests\Unit;
use App\User;
use App\Enums\RBAC;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
<?php
namespace App;
use App\Enums\RBAC;
use BenSampo\Enum\Traits\CastsEnums;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
<?php
namespace App\Enums;
use App\User;
use BenSampo\Enum\FlaggedEnum;
use function collect;
use function is_object;
final class RBAC extends FlaggedEnum
@sasin91
sasin91 / AutomappingPermissionsTest.php
Last active July 21, 2019 08:59
Auto mapping permissions to policies
<?php
namespace Tests\Unit\Authorization;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class AutomappingPermissionsTest extends TestCase
{
use RefreshDatabase;
@sasin91
sasin91 / make_windows_usb.sh
Created October 28, 2018 10:26
./make_windows_usb.sh /dev/sdx /storage/Win10_x64.iso
#! /bin/bash
# A very simple, primitive and slightly assuming script for creating a bootable windows 10 USB key.
# First we'll prepare the USB
parted mklabel gpt $1
mkfs.fat32 $11
# Then create the directories...
mkdir -p /mnt/Windows10_source
mkdir -p /mnt/Windows10_target
@sasin91
sasin91 / Archive.php
Created September 25, 2018 15:53
Create archives with a pretty fluent syntax
<?php
namespace App;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use Phar;
use PharData;
use function is_dir;
use function is_file;
@sasin91
sasin91 / RemovesInvalidNestedValues
Created July 16, 2018 14:17
Strip invalid nested values from data validated in a form request
<?php
namespace App\Http\Requests;
use function array_dot;
use function fnmatch;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
@sasin91
sasin91 / HasModelStates.php
Created July 12, 2018 09:48
Factory model story with model states
<?php
trait HasModelStates
{
/**
* The registered model states.
*
* @var array
*/
protected $states = [];
@sasin91
sasin91 / toFlatValuePairs.php
Created July 10, 2018 12:26
Map a collection into paired values while retaining the key
<?php
use Illuminate\Support\Collection;
/**
* Map the values of given collection into a collection of each pair, retaining the key.
*
* @return Collection
*/
Collection::macro('toFlatValuePairs', function () {
@sasin91
sasin91 / DatabaseOptimizeCommand.php
Created June 11, 2018 13:08
Defragment your MySQL database
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class DatabaseOptimizeCommand extends Command
{