Skip to content

Instantly share code, notes, and snippets.

View EduardoSP6's full-sized avatar

Eduardo P. Sales EduardoSP6

  • Maricá - RJ
  • 01:27 (UTC -03:00)
View GitHub Profile
@EduardoSP6
EduardoSP6 / custom_auth_provider_laravel.md
Last active October 8, 2025 23:29
How to create a custom auth provider in Laravel

How to create a custom auth provider in Laravel

Imagine the following situation: in an API implemented in PHP and Laravel, we need to create an entity for users who are authenticated in another specific API, which provides only user data and not an authentication token.

This is a fairly common situation for most developers these days, and if you haven't experienced it yet, rest assured, that day will come soon.

Well, in this case, it's recommended that, in addition to implementing an internal authentication layer without using the User model, we also implement authentication token generation and user session management.

So, what we'll use is:

  • PHP 8.x;
@EduardoSP6
EduardoSP6 / laravel-bootstrap-paginator-with-filters.md
Last active July 22, 2025 23:43
Laravel bootstrap paginator with filters

Laravel and Bootstrap paginator with filters

Problem:

When creating a record listing page with filters using Laravel and Blade with Bootstrap 4, we encounter the following situation:

The pagination works perfectly, but after applying a filter and changing the page, the previously applied filter is lost. This occurs because Laravel's pagination already includes page links in the query parameters on the front-end, overriding the filters that are currently in the same location.

@EduardoSP6
EduardoSP6 / cnpj-validator.php
Created April 30, 2025 18:20
CNPJ Validator PHP
<?php
namespace App\Domain\Shared\Validators;
class CnpjValidator
{
public static function execute(string $cnpj): bool
{
$cnpj = str_pad($cnpj, 14, '0', STR_PAD_LEFT);
@EduardoSP6
EduardoSP6 / implementing_pagination_php_and_spatie_query_builder.md
Last active February 28, 2025 21:54
Implementing pagination in PHP with Spatie Query Builder + React Tanstack Table

Implementing pagination in PHP with library Spatie Query Builder + React Tanstack Table

Tested with:

Back-end implementation:

@EduardoSP6
EduardoSP6 / prevent-pull-to-refresh.md
Last active January 14, 2025 21:42
Prevent pull to refresh - React.js | Javascript

How to Prevent Page Refresh When Swiping Down on Mobile

In many mobile browsers, a "pull down" gesture at the top of the page can trigger the "pull-to-refresh" functionality. While useful in some scenarios, this behavior can be undesirable in web applications that utilize touch elements or where the page should not be reloaded.

We can use touch events (touchstart and touchmove) to detect when the user tries to "pull down" from the top of the page. In this case, we can prevent the default refresh action, ensuring that normal scrolling continues to work.

To do this, I created the component below:

@EduardoSP6
EduardoSP6 / PdfToText.php
Last active January 8, 2025 16:14
How to convert PDF to Text with Tesseract OCR
<?php
namespace Infrastructure\Utils\OCR;
use Exception;
use Imagick;
use ImagickException;
use RuntimeException;
use thiagoalessio\TesseractOCR\TesseractOCR;
@EduardoSP6
EduardoSP6 / object_props_to_array.php
Last active January 8, 2025 16:23
Method to convert object properties to array in PHP
<?php
public function __toArray(): array
{
return call_user_func('get_object_vars', $this);
}
@EduardoSP6
EduardoSP6 / csv_to_array.php
Last active January 28, 2022 16:04
PHP function to convert CSV file content to array
<?php
function csvToArray($filename = '', $delimiter = '\t')
{
if (!file_exists($filename) || !is_readable($filename))
return [];
$row = 0;
$fileContent = [];
if (($handle = fopen($filename, "r")) !== FALSE) {
@EduardoSP6
EduardoSP6 / verify_email_laravel_7.md
Last active January 8, 2025 18:26
Custom e-mail verification Laravel 7

Implementação de rotina de verificação da conta de e-mail

  • Criar migração do model User adicionando o campo:
$table->timestamp('email_verified_at')->nullable();
  • Implementar a interface MustVerifyEmail no model User;
@EduardoSP6
EduardoSP6 / custom_password_rules_laravel7.md
Last active January 8, 2025 18:31
Custom password validation laravel 7

Custom password validation laravel 7:

For create a custom password rule for laravel you should run a command: php artisan make:rule PasswordRule. The class will be created in App\Rules folder.

Example:

<?php