Skip to content

Instantly share code, notes, and snippets.

@ctf0
ctf0 / -laravel tips.md
Last active October 21, 2023 05:41
laravel tips
  • php assoc array to correct js array of objs
$data = [
    'Users' => 'abc',
    'posts' => 'blabla',
];

collect($data)->map(function ($v, $k) {
 return [
@ctf0
ctf0 / paginate.php
Last active October 20, 2021 01:05 — forked from vluzrmos/paginate.php
Laravel Paginate Collection or Array
<?php
// use Illuminate\Support\Collection;
// use Illuminate\Pagination\Paginator;
// use Illuminate\Pagination\LengthAwarePaginator;
/**
* Gera a paginação dos itens de um array ou collection.
*
* @param array|Collection $items

Dont

  • hash the id on either boot::retrieved or getIdAttribute() because delete() & forceDelete() wont work as they create a new query which will keep getting the same hashed id

  • use Route::bind in the service provider as its applying the bind globally.

Maybe

  • save the hashed id to the db same as UUID but if u r using mysql, indexing will suffer
<?php
namespace App\Traits;
use Fico7489\Laravel\Pivot\Traits\PivotEventTrait;
use OwenIt\Auditing\Auditable;
/**
* https://gist.github.com/AbbyJanke/4d245b22dbcec277c207f033f37dae3b.
*/
@ctf0
ctf0 / invisible recaptcha.md
Last active October 31, 2022 09:37
invisible recaptcha with vuejs & laravel

Frontend "https://github.com/DanSnow/vue-recaptcha"

  • npm install --save vue-recaptcha

  • form

<my-form inline-template>
    <form action="{{ route('...') }}" @submit.prevent="FormSubmit($event)">
        // other inputs
<?php
namespace App;
use Closure;
class CommandEventsListener
{
protected $startCallbacks = [];
protected $finishCallbacks = [];

position sticky

for normal usage

parent shouldnt have

  • height
  • overflow

for flex, the direct parent should have "try without first"

  • align-self: flex-start;
@ctf0
ctf0 / vue tips.md
Last active December 10, 2019 03:28

Js

  • clones
// to clone an object
this.x = Object.assign({}, this.y)

// to clone an array
this.x = this.y.slice(0)
  • we dont use @input to save changes as it will reset the cursor, so we use @blur instead
<td contenteditable dir="auto"
    v-html="someText"
    @keydown.enter.prevent
    @input="newEntry()"
    @blur="saveNewValue($event)">
</td>
<?php
function getFilePath($disk, $filename)
{
$config = config("filesystems.disks.$disk");
$url = app('filesystem')->disk($disk)->url($filename); // get the file url
$root = array_get($config, 'root');
// for other disks without root ex."cloud"
if (!$root){