Skip to content

Instantly share code, notes, and snippets.

View PierreLebedel's full-sized avatar

Pierre Lebedel PierreLebedel

View GitHub Profile
@PierreLebedel
PierreLebedel / AppServiceProvider
Last active October 14, 2024 12:50
Pluck Laravel collection by unique field (Typically User's First Name)
public function boot(): void
{
Collection::macro('pluckUnique', function (string $firstAttribute, string $secondAttribute, $glue = null) {
return $this->map(function ($item) use ($firstAttribute, $secondAttribute) {
$item->firstAttributeCleaned = Str::lower($item->{$firstAttribute});
$item->secondattributeCleaned = Str::lower($item->{$secondAttribute});
return $item;
})->mapWithKeys(function ($value, $key) use ($firstAttribute, $secondAttribute, $glue) {
@PierreLebedel
PierreLebedel / toast-message.blade.php
Last active October 3, 2024 09:35
TallStackUI component to show toast message on Livewire event (to replace Jetstream action-message component for example)
@props(['on', 'method'=>'success', 'title'=>null])
@php
if( !in_array($method, ['success', 'warning', 'error', 'info']) ){
$method = 'info';
}
if( empty($title) && $slot->isEmpty() ){
$title = __('Success');
}
@endphp
@PierreLebedel
PierreLebedel / ViewServiceProvider.php
Created February 8, 2024 13:06
Blade directive for @price (EUR)
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
final class ViewServiceProvider extends ServiceProvider
{
public function boot(): void
@PierreLebedel
PierreLebedel / Envoy.blade.php
Last active February 8, 2024 08:57
Laravel Envoy config for staging & production
@servers([
'staging' => '[email protected] -p 22',
'production' => '[email protected] -p 22',
])
@setup
if (empty($server)) {
exit('ERROR: envoy run option --server is undefined'.PHP_EOL);
}
if($server=='production'){
@PierreLebedel
PierreLebedel / .env
Last active January 28, 2024 15:54
Configuration files for beyondcode/laravel-websockets:1.14.1 on Laravel 10 with Supervision and SSL on Apache 2.4
PUSHER_APP_ID=examplesite-appid
PUSHER_APP_KEY=examplesite-appkey
PUSHER_APP_SECRET=examplesite-appsecret
PUSHER_APP_CLUSTER=mt1
PUSHER_HOST=www.examplesite.com
PUSHER_PORT=6001
PUSHER_SCHEME=http
LARAVEL_WEBSOCKETS_PORT=443
LARAVEL_WEBSOCKETS_VERIFY_PEER=false
@PierreLebedel
PierreLebedel / app.scss
Created January 26, 2024 13:50
Tabler.io styles for table tbody
@import "../../node_modules/@tabler/core/src/scss/tabler.scss";
.table {
tfoot {
th {
color: $table-th-color;
background: $table-th-bg;
font-weight: var(--#{$prefix}font-weight-bold);
text-transform: uppercase;
letter-spacing: .04em;
@PierreLebedel
PierreLebedel / datepickr.scss
Created January 18, 2024 09:15
Datepickr - Bootstrap5 theme
.flatpickr-calendar {
.numInputWrapper {
.arrowUp,
.arrowDown {
width: 20px;
padding: 0;
&:after {
@PierreLebedel
PierreLebedel / tailwind.blade.php
Last active December 21, 2023 15:30
Livewire pagination for daisyUI
@php
if (! isset($scrollTo)) {
$scrollTo = 'body';
}
$scrollIntoViewJsSnippet = ($scrollTo !== false)
? <<<JS
(\$el.closest('{$scrollTo}') || document.querySelector('{$scrollTo}')).scrollIntoView()
JS
: '';
@PierreLebedel
PierreLebedel / php
Created May 1, 2021 08:19
WordPress: add page template from custom plugin
<?php
/**
* Plugin Name: Page templates from plugin
* Plugin URI:
* Description: Page templates from plugin
* Version: 1.0.0
* Author: Pierre Lebedel
* Author URI: https://www.pierrelebedel.fr
*/
@PierreLebedel
PierreLebedel / FrenchHolidays.php
Created October 18, 2019 10:12
Calcul et affichage des jours fériés en France
<?php
/**
* Jours fériés en France
* Source : https://phpsources.net/code/php/date-heure/641_jours-feries-en-france
*/
class FrenchHolidays {
public static function isHoliday($day=false, $alsacemoselle=false){