Skip to content

Instantly share code, notes, and snippets.

View ArielMejiaDev's full-sized avatar
🐘
Focusing

ArielMejiaDev ArielMejiaDev

🐘
Focusing
View GitHub Profile
@oscar-broman
oscar-broman / gist:3653399
Created September 6, 2012 09:05
UTF8 encode array/object structure in PHP
<?php
function utf8_encode_deep(&$input) {
if (is_string($input)) {
$input = utf8_encode($input);
} else if (is_array($input)) {
foreach ($input as &$value) {
utf8_encode_deep($value);
}
unset($value);
@RuGa
RuGa / massInsertOrUpdate.php
Last active June 3, 2024 15:50
Mass (bulk) insert or update on duplicate for Laravel 4/5
/**
* Mass (bulk) insert or update on duplicate for Laravel 4/5
*
* insertOrUpdate([
* ['id'=>1,'value'=>10],
* ['id'=>2,'value'=>60]
* ]);
*
*
* @param array $rows
@PurpleBooth
PurpleBooth / README-Template.md
Last active June 17, 2024 09:56
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@SrcFlux
SrcFlux / NamespaceHelper.php
Created October 2, 2015 11:43
Get the namespace of a class in Laravel
<?php
namespace App\Helpers;
class NamespaceHelper
{
/**
* Get the namespace of a class.
*
* @param string $className
@vluzrmos
vluzrmos / paginate.php
Created July 20, 2016 14:31
Laravel Paginate Collection or Array
<?php
/**
* Gera a paginação dos itens de um array ou collection.
*
* @param array|Collection $items
* @param int $perPage
* @param int $page
* @param array $options
*
* @return LengthAwarePaginator
@simonhamp
simonhamp / AppServiceProvider.php
Last active June 12, 2024 11:05
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@jnbn
jnbn / controller.php
Last active May 17, 2024 03:31
Replicate (Duplicate) Eloquent Model With Relations
<?php
public function replicateWithRelations(QuestionCategory $questioncategory)
{
$newCategory = $questioncategory->replicate();
$newCategory->name = "Kopyası: ".$questioncategory->name;
$newCategory->push();
$questioncategory->relations = [];
//load relations on EXISTING MODEL
@branflake2267
branflake2267 / main.dart
Last active June 22, 2022 02:41
Flutter fonts example use.
import 'package:flutter/material.dart';
const String words1 = "Almost before we knew it, we had left the ground.";
const String words2 = "A shining crescent far beneath the flying vessel.";
const String words3 = "A red flair silhouetted the jagged edge of a wing.";
const String words4 = "Mist enveloped the ship three hours out from port.";
void main() {
runApp(new MyApp());
}
@jeffochoa
jeffochoa / Response.php
Last active May 22, 2024 04:06
Laravel HTTP status code
<?php
// This can be found in the Symfony\Component\HttpFoundation\Response class
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
@aslrousta
aslrousta / PessimistTransaction.php
Last active June 1, 2024 03:50
Pessimistic Locking for Transaction
<?php
function transfer($fromAccountId, $toAccountId, $amount)
{
DB::beginTransaction();
try {
$fromQuery = Account::whereId($fromAccountId);
if (! $fromQuery->exists()) {
throw new InvalidAccountException();