Skip to content

Instantly share code, notes, and snippets.

View paulofreitas's full-sized avatar

Paulo Freitas paulofreitas

  • I'm my own boss
  • Brazil
  • 22:44 (UTC -03:00)
View GitHub Profile
@paulofreitas
paulofreitas / Handler.php
Last active May 16, 2017 22:28
A custom package/module exception handler that decorates the Laravel's app exception handler. And also a nice introduction to the Decorator and Chain of Responsibility design patterns.
<?php
namespace Package\Exceptions;
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler as HandlerContract;
class Handler implements HandlerContract
{
/**
@paulofreitas
paulofreitas / HandleCorsMiddleware.php
Created March 30, 2017 23:10
CORS middleware example
<?php
namespace App\Http\Middleware;
class HandleCorsMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
@paulofreitas
paulofreitas / User.php
Last active May 16, 2017 22:05
Self-relationships through pivot tables
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
@paulofreitas
paulofreitas / ValidationServiceProvider.php
Last active March 7, 2017 23:35
Using custom Validator in Laravel
<?php // app/Providers/ValidationServiceProvider.php
namespace App\Providers;
use App\Validation\Validator;
use Illuminate\Support\ServiceProvider;
class ValidationServiceProvider extends ServiceProvider
{
public function boot()
@paulofreitas
paulofreitas / oss-contributions.md
Last active September 22, 2017 15:23
My open-source contributions

My open-source contributions

Bugs/issues reported, pull requests contributed and stuff like that, pushed here and there.

72 contributions so far:

<?php
class GeoJSON
{
public function __construct(string $geojson)
{
$this->_struct = json_decode($geojson);
}
public static function fromString(string $geojson)
@paulofreitas
paulofreitas / transposing_form_input.php
Last active February 22, 2017 05:41
Laravel collection macro to transpose form data extracted from Refactoring to Collections book
<?php
/* Transpose Macro */
Collection::macro('transpose', function () {
$items = array_map(function (...$items) {
return $items;
}, ...$this->values());
return new static($items);
});
<?php
use Carbon\Carbon;
class DateUtils extends Carbon
{
public function isSameWeek(Carbon $dt)
{
return $this->weekOfYear === $dt->weekOfYear;
}
<?php
/**
* Laravel trait to allow aliasing table fields.
*
* @author Paulo Freitas <[email protected]>
*/
namespace App;