Skip to content

Instantly share code, notes, and snippets.

View xxRockOnxx's full-sized avatar

Lemuel Flores xxRockOnxx

View GitHub Profile
@xxRockOnxx
xxRockOnxx / laravel-telescope-auth.md
Created October 4, 2024 21:55
Laravel Telescope custom authorization

Laravel Telescope custom authorization

By default, Laravel Telescope allows you to visit the /telescope route if:

  • environment is local
  • passes the viewTelescope Gate check

By tracing how Telescope does it Authorization, I've found:

  • It declares middlewares in its config file: Link
@xxRockOnxx
xxRockOnxx / laravel-tinker-login-session.md
Last active October 28, 2024 01:39
Laravel Tinker: login as another user and generate an injectable session cookie

Generating session cookie

  1. Enter Laravel Tinker
php artisan tinker
  1. Authenticate
@xxRockOnxx
xxRockOnxx / demo.vue
Last active October 4, 2022 13:34
Vue Composition vs Options API
<template>
<UsersRepo>
<template v-slot="{ isLoading, fetch, users }">
<button
v-if="users.length === 0"
@click="fetch"
>
Fetch Users
</button>
@xxRockOnxx
xxRockOnxx / scoped-events.ts
Last active July 5, 2022 10:55
Node.js EventEmitter that scopes events by suffix
import { EventEmitter } from 'events';
export default function scopeEventEmitter(events: EventEmitter, scope: string): EventEmitter {
return {
eventNames: () => events.eventNames().filter((name) => typeof name === 'string' && name.endsWith(`:${scope}`)),
on(event: string, listener) {
events.on(`${event}:${scope}`, listener);
return this;
},
@xxRockOnxx
xxRockOnxx / layouts.ts
Last active April 27, 2020 13:49
React Native Navigation with react-native-vector-icons
interface Layouts {
[name: string]: LayoutRoot;
}
const layouts: Promise<Layouts> = new Promise(resolve => {
Promise.all([
Icon.getImageSource("people"),
Icon.getImageSource("message")
]).then(icons => {
resolve({
@xxRockOnxx
xxRockOnxx / Handler.php
Last active January 20, 2021 21:35
[Laravel] Convert dot array validation error to nested array
<?php
namespace App\Exceptions;
class Handler
{
/**
* Convert a validation exception into a JSON response.
*
* @param \Illuminate\Http\Request $request
@xxRockOnxx
xxRockOnxx / validateDay.php
Last active September 27, 2023 23:40
[Laravel] Custom Validation rule for day of week.
<?php
Validator::extend('day', function($attribute, $value, $parameters, $validator) {
// Laravel uses Carbon. Just `use Carbon\Carbon;` it
$day = Carbon::parse($value)->dayOfWeek;
switch (strtolower($parameters[0])) {
case 'sunday':
return $day == 0;
@xxRockOnxx
xxRockOnxx / Handler.php
Last active July 14, 2018 03:18
[Laravel] Custom Error Page based on route (Public and Admin error page)
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
// Don't forget to add this line as it is used by renderHttpException()
use Symfony\Component\HttpKernel\Exception\HttpException;