Skip to content

Instantly share code, notes, and snippets.

View colindecarlo's full-sized avatar

Colin DeCarlo colindecarlo

  • Guelph, Ontario, Canada
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<?php
namespace Tests;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Validator;
use Symfony\Component\HttpFoundation\ParameterBag;
use function PHPUnit\Framework\assertFalse;
@colindecarlo
colindecarlo / babel-private-attributes.js
Created November 15, 2020 16:25
My implementation of private class attributes in JavaScript and Babel's implementation
/**
* The good people at the Babel project opted to use global-ish variables (`WeakMap`s) and functions
* to track the private attributes of class instances.
*
* Looking at the implementation, I think the functions used to access the private attributes of the
* classes allow you to have private getters and setters (not sure why you might want that, perhaps
* for internally accessible computed properties) but it sure is neat.
*/
"use strict";
<?php
namespace Vehikl\Feature\Tests;
use PHPUnit\Framework\TestCase;
class FeatureToggleTest extends TestCase
{
public function test_it_executes_the_on_method_when_the_feature_is_on()
{
@colindecarlo
colindecarlo / Foo.php
Created April 18, 2018 23:09
Arbitrarily deeply nested parent child relationships with eloquent
<?php
use Illuminate\Eloquent\Model;
class Foo extends Model
{
protected $attributes = [
'parent_id' => null,
];
<?php
class Event
{
public function fights()
{
return $this->hasMany(Fight::class)->orderBy('fightcard_order');
}
public function topFight()
@colindecarlo
colindecarlo / FiltersRequests.php
Created April 8, 2017 14:50
Plug'n'play filter trait for filtering resources in your controllers
<?php
namespace App\Http;
/**
* ?filter[foo]=bar&filter[qux]=baz
*/
trait FiltersRequests
{
private function filter($query)
diff --git a/routes/api.php b/routes/api.php
index 6b907f3..0e8d957 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -13,6 +13,11 @@ use Illuminate\Http\Request;
|
*/
-Route::get('/user', function (Request $request) {
- return $request->user();
<?php
function expiryDates() {
$january = Carbon::now()->startOfYear();
$eachMonth = new DateInterval('P1M');
$december = Carbon::now()->endOfYear();
return collect(new DatePeriod($january, $eachMonth, $december))->map(function ($date) {
return $date->format('m/Y');
});
}
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTitlesTable extends Migration
{
/**
* Run the migrations.
*