Skip to content

Instantly share code, notes, and snippets.

View martinbean's full-sized avatar

Martin Bean martinbean

View GitHub Profile
@martinbean
martinbean / AppServiceProvider.php
Last active March 1, 2018 11:06
Disable Bugsnag in certain environments
<?php
namespace App\Providers;
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@martinbean
martinbean / test.php
Created February 6, 2018 18:34
Throw a validation exception with a plain array of errors
<?php
use Illuminate\Validation\ValidationException;
if ($coupon->cannotBeRedeemed()) {
throw ValidationException::withMessages([
'coupon' => [
'The coupon code is invalid.',
],
]);
@martinbean
martinbean / confirm.js
Created November 27, 2017 23:22
Vue.js confirm mixin
module.exports = {
methods: {
confirm(message, callback) {
if (window.confirm(message)) {
callback();
}
}
}
};
@martinbean
martinbean / ExampleTest.php
Created November 16, 2017 13:55
TestResponse fromJsonString() macro
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\TestResponse;
use Tests\TestCase;
class ExampleTest extends TestCase
{
public function testExample()
@martinbean
martinbean / install-autoconf.sh
Created October 31, 2017 10:30
Install autoconf on macOS
#!/bin/sh
cd ~/
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
cd autoconf-latest
./configure --prefix=/usr/local
make
sudo make install
@martinbean
martinbean / Registrar.php
Last active September 1, 2017 15:47
Laravel 5 registrar service, improved
<?php namespace App\Services;
use App\Contracts\UserRepository;
use App\User;
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Illuminate\Contracts\Validation\Validator;
class Registrar implements RegistrarContract {
@martinbean
martinbean / ForceSecure.php
Created June 28, 2017 13:11
Redirect non-secure requests on Heroku
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class ForceSecure
{
/**
@martinbean
martinbean / BladeServiceProvider.php
Created June 24, 2017 10:56
Admin Blade directive
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
@martinbean
martinbean / Article.php
Created January 3, 2017 16:41
Request-driven development
<?php
namespace App\News;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function publish()
{
@martinbean
martinbean / BladeServiceProvider.php
Last active October 26, 2016 11:32
Laravel Blade directive for FontAwesome icons.
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**