$tourist = Tourist::updateOrCreate([...]);
if(!$tourist->wasRecentlyCreated && $tourist->wasChanged()){
// updateOrCreate performed an update
}
if(!$tourist->wasRecentlyCreated && !$tourist->wasChanged()){
// updateOrCreate performed nothing, row did not change
}
View laravel_check_if_update_or_create_perfomed_update.md
View row_to_json_example.md
SELECT json_agg(row_to_json(ROW)) AS treeeeeee
FROM (
SELECT * FROM table_name
) row
View row_to_json_postgreSQL.md
SELECT
json_build_object(
'id', u.id,
'name', u.name,
'email', u.email,
'user_role_id', u.user_role_id,
'user_role', json_build_object(
'id', ur.id,
View create-decorators-typescript.md
Don´t forget to set up experimentalDecorators as a true value into the compileOptions attribute in the tsconfig.json file.
Call this decorator before method as @decoratorName()
export function decoratorName(paramName : boolean = false) {
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
View replacing-objects-array-javascript.md
I need to replace objects in arr1 with items from arr2 with same id
var arr1 = [
{ id: '124', name: 'qqq'},
{ id: '589', name: 'www'},
{ id: '45', name: 'eee'},
{ id: '567', name: 'rrr'}
];
View remove-object-array-of-objects-javascript.md
If you want to remove one object using only the id property
## I need to replace objects in arr1 with items from arr2 with same id
const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
View all-months-with-two-dates-carbon.md
<?php
public function getMonthListFromDate(Carbon $start)
{
$start = $start->startOfMonth();
$end = Carbon::today()->startOfMonth();
do
{
View transactions-multiple-connections-lumen.md
$cn = DB::connection('pgsql-private');
$cn->beginTransaction();
try {
$create = $this->create([
'fk_user_id' => $user_id,
]);
if (! $create) {
View laravel-collection-group-with-sum-values.md
<?php
$mystuff = collect($something);
$num = $mystuff->groupBy('dateDay')->map(function ($row) {
return $row->sum('n');
});
dd($num);
View with-recursive-postegreSQL.md
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
NewerOlder