Skip to content

Instantly share code, notes, and snippets.

View martinbean's full-sized avatar

Martin Bean martinbean

View GitHub Profile
@martinbean
martinbean / webpack.mix.js
Created May 17, 2018 14:17
Vendor library extraction in Laravel Mix
let mix = require('laravel-mix');
mix.sass('resources/assets/sass/app.scss', 'public/css')
.js('resources/assets/js/app.js', 'public/js')
.js('resources/assets/js/channel-admin.js', 'public/js')
.js('resources/assets/js/video.js', 'public/js')
.extract(['jquery', 'bootstrap'])
.options({ processCssUrls: false })
.sourceMaps();
vendor/bin/phpunit --printer="PHPUnit\TextUI\ResultPrinter"
@martinbean
martinbean / ArticleController.php
Created March 26, 2018 13:35
Using Laravel’s Responsable interface to create view models
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Http\Views\ArticleIndex;
class ArticleController extends Controller
{
public function index()
@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 / 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
{
/**