Skip to content

Instantly share code, notes, and snippets.

View mknparreira's full-sized avatar

Maikon Parreira mknparreira

View GitHub Profile
@mknparreira
mknparreira / laravel-all-months-with-two-dates-carbon.md
Last active August 12, 2021 22:13
Laravel | Getting all months between 2 dates Carbon
public function getMonthListFromDate(Carbon $start)
{
    $start = $start->startOfMonth();
    $end   = Carbon::today()->startOfMonth();

    do
    {
 $months[$start->format('m-Y')] = $start->format('F Y');
@mknparreira
mknparreira / lumen-transactions-multiple-connections.md
Last active August 12, 2021 22:14
Lumen | How to use Transactions with multiple connections
        $cn = DB::connection('pgsql-private');
        $cn->beginTransaction();

        try {
            $create = $this->create([
                'fk_user_id' => $user_id,
            ]);

            if (! $create) {
@mknparreira
mknparreira / laravel-collection-group-with-sum-values.md
Last active August 12, 2021 22:15
Laravel | Collection group with sum values
$mystuff = collect($something);
$num = $mystuff->groupBy('dateDay')->map(function ($row) {
    return $row->sum('n');
});

dd($num);
@mknparreira
mknparreira / postegre-with-recursive.md
Last active August 12, 2021 22:16
PostegreSQL | With Recursive
WITH RECURSIVE supplytree AS
(
	SELECT 
		id,
		description, 
		parent_feature_id,
		to_jsonb(feature) AS si_object,
		CAST(description As varchar(1000)) AS si_fullname 
	FROM feature
@mknparreira
mknparreira / php-array-replace-recursive.md
Last active August 12, 2021 22:16
PHP | Array Replace Recursive Example
$arr1 = [
    1 => [
        'mes' => null,
        'valor' => null,
        'consumo' => null,
    ],

    2 => [
@mknparreira
mknparreira / laravel-create-singleton-laravel.md
Last active August 12, 2021 22:17
Laravel | Creating a Singleton pattern
//AppServiceProvider
$this->app->singleton('FooBar', function ($app) {
            return $app;
        });

//Anywhere
$this->app->instance('FooBar', ['name' => 'Maikon', 'age' => 15]);
@mknparreira
mknparreira / php-mess-detector-ruleset.md
Last active August 12, 2021 22:18
PHP Mess Detector ruleset.xml
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pcsg-generated-ruleset"
         xmlns="http://pmd.sf.net/ruleset/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
         xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>
        My custom rule set that checks my code...
    </description>
@mknparreira
mknparreira / php-bug-fix-unknown-failed-opening-required-on-line-0.md
Last active August 12, 2021 22:19
PHP | Bug fix Unknown Failed opening required on line 0

Introduction

Sometimes can occoured an error just like this:

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'C:\xampp\htdocs\NC World\ProjectName\server.php' 
(include_path='C:\xampp\php\PEAR') in Unknown on line 0

To fix this, must create a file called index.php and put on public/ dir

@mknparreira
mknparreira / php-cs-fixer-example-2.md
Last active August 12, 2021 22:19
PHP CS Fixer | Example 2
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->name('*.php')
    ->notName('_ide_helper.php')
    ->notName('*.blade.php')
    ->notPath('bootstrap')
    ->notPath('node_modules')
    ->notPath('storage')
@mknparreira
mknparreira / linux-edit-host.md
Last active August 12, 2021 22:20
Linux | Editing a host

Open the cmd (Ctrl + Alt + T) and do the following command

sudo nano /etc/hosts

and add

127.0.0.1 .