Skip to content

Instantly share code, notes, and snippets.

View cookavich's full-sized avatar
🎯
Focusing

Paul Cook cookavich

🎯
Focusing
View GitHub Profile
@cookavich
cookavich / laravel-cors.php
Created August 17, 2017 18:11 — forked from adamwathan/laravel-cors.php
Need to do something like this to serve APIs that are going to be consumed by JS clients.
<?php
App::before(function($request) {
if ($request->getMethod() == 'OPTIONS') {
$response = Response::make('', 204);
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS');
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
return $response;
}
@cookavich
cookavich / maxBy.php
Created August 17, 2017 18:10 — forked from adamwathan/maxBy.php
maxBy/minBy macros
<?php
Collection::macro('maxBy', function ($callback) {
$callback = $this->valueRetriever($callback);
return $this->reduce(function ($result, $item) use ($callback) {
if ($result === null) {
return $item;
}
return $callback($item) > $callback($result) ? $item : $result;
<?php
namespace App\Merge;
class Marge
{
protected $data = [];
public function setData($data)
{