Skip to content

Instantly share code, notes, and snippets.

View Butochnikov's full-sized avatar

Alexey Butochnikov

  • Russia
  • 14:54 (UTC +03:00)
View GitHub Profile
@jonneroelofs
jonneroelofs / EventForm.php
Created December 21, 2021 13:04
Flatpickr wrapped with Alpine.js in blade component for Laravel Livewire
<?php
namespace App\Http\Livewire;
use App\Models\Event;
use Livewire\Component;
class EventForm extends Component
{
public $event;
@reinink
reinink / query.sql
Last active November 14, 2023 11:08
Text search across multiple tables using MySQL
select
first_name,
last_name
from
users
left join
companies on companies.id = users.company_id
where (
companies.name like 'TERM%' or
first_name like 'TERM%' or
CENTRIFUGO=/usr/bin/centrifugo
CENTRIFUGO_ARGS="--config=/etc/centrifugo/config.json --log_file=/var/log/centrifugo.log"
PIDFILE=/var/run/centrifugo.pid
case "$1" in
start)
echo -n "Starting Centrifugo"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $CENTRIFUGO -- $CENTRIFUGO_ARGS
echo "."
;;
stop)
@themsaid
themsaid / controller.md
Created March 23, 2020 09:49
OG post images

require "stil/gd-text": "^1.1",

class ControllerClass extends Controller
{
    public function __invoke($slug)
    {
        $post = WinkPost::where('slug', $slug)->first();
        $quickDip = $post->tags()->whereSlug('quick-dip')->first() ;
<?php
use Illuminate\Database\Query\Builder;
Builder::macro('orderByNulls', function ($column, $direction = 'asc', $nulls = 'last', $bindings = []) {
$column = $this->getGrammar()->wrap($column);
$direction = strtolower($direction) === 'asc' ? 'asc' : 'desc';
$nulls = strtolower($nulls) === 'first' ? 'NULLS FIRST' : 'NULLS LAST';
return $this->orderByRaw("$column $direction $nulls", $bindings);
});
@calebporzio
calebporzio / error_blade_directive.php
Created March 28, 2019 20:34
A little Blade directive to make working with validation errors a bit nicer.
<?php
// Usage:
// Before
@if ($errors->has('email'))
<span>{{ $errors->first('email') }}</span>
@endif
// After:
@calebporzio
calebporzio / HiddenInput.vue
Created May 2, 2018 14:47
Little Vue component for turning JSON into native HTML for inputs
<script>
import _ from 'lodash'
export default {
props: [ 'name', 'value' ],
methods: {
flatInputsFromDeepJson(item, key, h) {
if (typeof item === 'object') {
return _.flatMapDeep(item, (value, newKey) => {
@butschster
butschster / debian-laravel.sh
Last active June 17, 2022 10:24
LEMP server configured for Laravel (MySQL, NGINX, php7.2-fpm, Redis, Websocket server, MongoDB, Composer)
# ================================================
# PHP 7.2
#
# See https://www.colinodell.com/blog/201711/installing-php-72
# ================================================
apt-get install -y apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
apt-get update
apt-get install -y php7.2-cli php7.2-gd php7.2-mbstring php7.2-curl php7.2-xml php7.2-zip
@adamwathan
adamwathan / 1-add-macros.php
Last active June 11, 2022 19:55
Multiformat Endpoints in Laravel
<?php
namespace App\Providers;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\ServiceProvider;
use App\Http\Middleware\CaptureRequestExtension;
class AppServiceProvider extends ServiceProvider
<?php
namespace App\Support\Http;
use Exception;
class ConfirmationException extends Exception
{
/**
* The recommended response to send to the client.