Skip to content

Instantly share code, notes, and snippets.

View Yannx79's full-sized avatar
:octocat:
Always learning, always growing.

Yannick Funes Yannx79

:octocat:
Always learning, always growing.
View GitHub Profile
// This is Pseudocode
function adjustOrder(list):
// Step 1: Adjust invalid values
for each element in list:
if element.order <= 0:
element.order = null // Mark as "no order"
// Step 2: Sort the list by 'order', moving null to the end
sort list by:
if a.order is null then return 1
@Yannx79
Yannx79 / Log.php
Last active July 26, 2024 22:22
Method to obtain the changes of a model in Laravel
<?php
if (!function_exists('getChanges')) {
function getChanges(Model $model, $original = null)
{
$hiddenFields = ['FechaRegistro', 'FechaModificacion', 'rbupdate', 'updated_at', 'created_at', 'Id'];
$modifiedModel = $model->replicate();
$originalModel = $original ? $original : $model->refresh();
$changes = ' se ha cambiado ';
foreach ($originalModel->getAttributes() as $key => $originalValue) {
if (in_array($key, $hiddenFields)) continue;