Skip to content

Instantly share code, notes, and snippets.

View zabaala's full-sized avatar
🏠
Working from home

Mauricio Rodrigues zabaala

🏠
Working from home
View GitHub Profile
@zabaala
zabaala / FormBuilder.php
Created April 12, 2016 17:42
Extends Illuminate\Html\FormBuilder
<?php
namespace M2Digital\Extras\Html;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Html\FormBuilder as IlluminateFormBuilder;
class FormBuilder extends IlluminateFormBuilder {
function slugify(str) {
str = str.toString().toLowerCase().trim()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-'); // Replace multiple - with single -
return str;
}
DROP IF EXISTS TABLE [tmp_table_name];
CREATE TABLE [tmp_table_name] engine=innodb (select * from [reference_table] where ...);
SELECT
TABLE_NAME AS `Table`,
ROUND(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '[schema]' AND TABLE_NAME = '[tmp_table_name]';
@zabaala
zabaala / eg.php
Created September 12, 2017 14:08
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class AplicacaoController extends Controller
{
private $session;
@zabaala
zabaala / TokenMismatchException.php
Last active October 19, 2017 13:59
Override Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php class
<?php
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
*/
public function handle($request, Closure $next)
input {
file {
path => "/data/logs/laravel/laravel.log"
start_position => "beginning"
type => "laravel_core_log"
codec => multiline {
pattern => "^\["
what => "previous"
negate => true
}
<?php
# Ex 2
use App\Applications\Backend\Http\Controllers\ExampleController;
Route::get('/{locale}/hackaton', function (\Illuminate\Http\Request $request) {
App::setLocale($request->locale);
return app(ExampleController::class)->callAction('index', []);
});
<?php
namespace App;
class CacheProductRepository extends ProductInterface
{
public function getAll()
{
// Get all products from redis...
}
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
class UFValidatorMiddleware
{
/**
* @const array
@zabaala
zabaala / Controller.php
Created January 26, 2018 11:23
Direct access to repository
<?php
class DoctorsController extends Controller
{
public function index(DoctorRepositoryInterface $doctorRepository)
{
$doctors = $doctorRepository->getAll('id', 'desc');
$total = $doctors->total();
// ...
}