Skip to content

Instantly share code, notes, and snippets.

<?php
Schema::table('clicks', function (Blueprint $table) {
$table->index('user_id');
$table->index(['user_id', 'date_clicked']);
$table->index(['user_id', 'date_clicked', 'ip']);
$table->index(['user_id', 'date_clicked', 'country']);
$table->index(['user_id', 'date_clicked', 'city']);
$table->index(['user_id', 'date_clicked', 'browser']);
@jarektkaczyk
jarektkaczyk / default.conf
Created December 16, 2018 00:33
NGiNX Configuration for Vue-Router in HTML5 Mode
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
server_name you.server.com;
@jarektkaczyk
jarektkaczyk / min-max.php
Created January 17, 2019 09:05
first/last/min/max on related table in Laravel Builder/Eloquent
<?php
$this->builder
->select('*') // needs to be here, otherwise the only returned column will be `last_login`
->selectSub(function ($q) {
$q->from('action_logs')
->whereColumn('user_id', 'users.id')
->selectRaw('max(created_at)');
}, 'last_login')
->get();
@jarektkaczyk
jarektkaczyk / DispatchableJobAssertion.php
Created May 19, 2020 05:05
Dispatchable incompatible with queue assertions?
<?php
// Laravel 7.*
// Testing jobs:
Queue::later(now()->addMinute(), new SomeJob);
Queue::assertPushed(SomeJob::class, fn () => ...); // works
SomeJob::dispatch()->delay(now()->addMinute());
<?php
// meh
$mock
->method('sum')
->withConsecutive([1,2,3], [4,5,6])
->willReturnOnConsecutiveCalls(6, 15);
// instead?
$mock->method('sum')->with(1,2,3)->willReturn(6);