Skip to content

Instantly share code, notes, and snippets.

View paulofreitas's full-sized avatar

Paulo Freitas paulofreitas

  • I'm my own boss
  • Brazil
  • 09:42 (UTC -03:00)
View GitHub Profile
@paulofreitas
paulofreitas / Apache Tricks.md
Last active July 21, 2017 18:00
Redirects Apache www URLs to non-www

Using mod_alias

HTTP only

<VirtualHost *:80>
    ServerName www.example.com
    Redirect permanent / http://example.com/
</VirtualHost>
<?php
namespace App;
use DB;
trait ExtendedModel
{
public static function getColumnInfo($column)
{
@paulofreitas
paulofreitas / HasCompositeKey.php
Last active June 24, 2017 00:19
Trait to enable the use of composite keys with Eloquent
<?php
namespace App\Entities;
use UnexpectedValueException;
use Illuminate\Database\Eloquent\Builder;
trait HasCompositeKey
{
/**
<?php
// Supondo que o formulário tenha um campo <input type="file" multiple /> chamado "images"
collect($request->images)->each(function ($image) {
// gera nome único para arquivo automaticamente (ex: 72237093253032091088276430939206.jpg) e salva na raiz
$filename = $image->storePublicly('.', 's3');
// usa nome original do arquivo, salva numa "pasta" para o artigo (ex: articles/3/cover.png)
$filename = $image->storePubliclyAs($image->getClientOriginalName(), "articles/{$article_id}", 's3');
<?php
class PostController
{
public function __controller(PostRepository $postRepository)
{
$this->postRepository = $postRepository;
}
public function index()
@paulofreitas
paulofreitas / VS Code.md
Last active August 1, 2022 04:55
My Visual Studio Code setup
@paulofreitas
paulofreitas / nginx-vhost-www.conf
Last active May 17, 2017 17:13
Nginx virtual host sample
server {
listen 80;
server_name www.dominio.com.br;
return 301 $scheme://dominio.com.br$request_uri;
}
<?php
// Requires Laravel
$json = <<<JSON
[{"name": "Taylor Otwell",
"country": {
"name": "United States"
}
},
<?php
$xml = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<Person>
<Name>{name}</Name>
<Age>{age}</Age>
<Gender>{gender}</Gender>
</Person>
XML;
@paulofreitas
paulofreitas / DatabaseTokenRepository.php
Last active April 6, 2017 03:00
Rollbacks Laravel's 5.4 password reset tokens patch (PR #16850: https://github.com/laravel/framework/pull/16850)
<?php // app/Support/Auth/Passwords/DatabaseTokenRepository.php
namespace App\Support\Auth\Passwords;
use Carbon\Carbon;
use Illuminate\Auth\Passwords\DatabaseTokenRepository as BaseRepository;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Auth\Passwords\TokenRepositoryInterface as RepositoryContract;
class DatabaseTokenRepository extends BaseRepository implements RepositoryContract