Skip to content

Instantly share code, notes, and snippets.

<?php
// Requires dependency: https://github.com/ralphjsmit/livewire-urls
if (!auth()->check()) {
$currentUrl = \RalphJSmit\Livewire\Urls\Facades\Url::current();
Session::put('url.intended', $currentUrl);
$this->redirectRoute('login');
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
const iconSvg = `<svg class="h-6 w-6 text-red-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"></path>
</svg>`;
Swal.fire({
showCancelButton: true,
buttonsStyling: false,
device_mac_address=XX-XX-XX
is_connected=$(/opt/homebrew/bin/blueutil --is-connected $device_mac_address)
if [[ "$is_connected" == 1 ]]; then
/opt/homebrew/bin/blueutil --disconnect $device_mac_address
else
/opt/homebrew/bin/blueutil --connect $device_mac_address
fi
<!-- Alpine Plugins -->
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/[email protected]/dist/cdn.min.js"></script>
<!-- Alpine Core -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
<div x-data="{ searchHistory: $persist([]).as('searchHistory') }" class="mx-auto max-w-sm bg-white py-8 px-6">
<form
@submit="
searchHistory.unshift($refs.searchInput.value)
<?php
namespace App\Jobs\Examples;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
<?php
// Livewire component
namespace App\Http\Livewire;
use App\Settings\GeneralSettings;
use Carbon\Carbon;
use Livewire\Component;
@aleksandertabor
aleksandertabor / json_apis_with_pagination_using_async_http_requests_in_laravel.php
Last active January 28, 2023 14:00
How to consume JSON APIs with pagination using async HTTP requests in Laravel?
<?php
$source = Http::get('https://rickandmortyapi.com/api/character');
$results = lazyJsonPages($source, 'results', static fn (Config $config): Config => $config
->items('info.count')
->perPage(20, 'page')
->concurrency(5)
);
@aleksandertabor
aleksandertabor / cte_laravel.php
Created January 14, 2023 23:53
How to group statistics data monthly using CTE (Common Table Expressions) in Laravel
<?php
use App\Models\Order;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Facades\DB;
use Staudenmeir\LaravelCte\Query\Builder;
$ordersData = Order::query()
->selectRaw("DATE_FORMAT(created_at, '%m/%Y') AS period, COUNT(*) AS orders_count")
->groupByRaw("DATE_FORMAT(created_at, '%m/%Y')");
@aleksandertabor
aleksandertabor / laravel_sail_tests_vscode_and_better_phpunit_plugin.json
Last active September 19, 2022 18:12
Laravel Sail - tests with Visual Studio Code and Better PHPUnit plugin
{
/**
* Better PHPUnit
**/
//? Command in Sail like "sail test":
"better-phpunit.phpunitBinary": "test",
// "better-phpunit.phpunitBinary": "phpunit",
"better-phpunit.docker.enable": true,
"better-phpunit.docker.command": "./vendor/bin/sail",
"better-phpunit.docker.paths": {