Skip to content

Instantly share code, notes, and snippets.

Jarek Tkaczyk jarektkaczyk

Block or report user

Report or block jarektkaczyk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jarektkaczyk / min-max.php
Created Jan 17, 2019
first/last/min/max on related table in Laravel Builder/Eloquent
View min-max.php
->select('*') // needs to be here, otherwise the only returned column will be `last_login`
->selectSub(function ($q) {
->whereColumn('user_id', '')
}, 'last_login')
jarektkaczyk / default.conf
Created Dec 16, 2018 — forked from szarapka/default.conf
NGiNX Configuration for Vue-Router in HTML5 Mode
View default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
View index_all_the_things.php
Schema::table('clicks', function (Blueprint $table) {
$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 / ExactMethodExpectation.php
Created Jul 16, 2018
PHPUnit - how to set expectations against exact methods calls
View ExactMethodExpectation.php
$mock = $this->createMock(SomeDependency::class);
$mock->expects($this->once())->method('secondMethod')->willReturn('something else');
$cut = new SomeClass($mock)
// how to ensure there's no method called other than the 2 above?
jarektkaczyk / SomeController.php
Created Jul 1, 2018
multi step validation in laravel
View SomeController.php
public function someController(Request $request)
// asumming ValidatesRequests trait in use we'll call $this->validate
$this->validate($request, [
// first set of rules
View check-children.php
$ids = array_unique([1,2,3,4,5, ...]);
// relation() is HasMany
// check if all $ids belong to this parent model:
$parent_model->relation()->whereIn('id', $ids)->count() === count($ids)
// check if $ids match all of the children records:
View gist:22716faa21f2ff15ba56018f9ed3481d
// assuming you want to get conv where last message doesn't come from the OP
Coversation::where('author_id', '!=', function ($q) {
$q->select('author_id')->from('messages')->whereRaw('conversation_id =')->latest()->limit(1);
View laravel-regex-in-route-params.php
// Do this (explicit routes are better):
Route::get('qualification', function () {/**/});
Route::get('qualification/{year}/{month}', function ($year, $month) {/**/});
// You could also do this (but don't in your case):
// @link
Route::get('qualification/{year_month?}', function ($year_month = null) {
jarektkaczyk / laravel-wheres-orWheres.php
Last active Apr 20, 2018
overlapping periods scope + how to nest orWhere in laravel query builder
View laravel-wheres-orWheres.php
// Freek posted a query today, that drives OhDearApp filters (the app recommended!):
// @link
// We can make the query more eloquent, so why don't we use a scope!
// I
// Let's make it really eloquent and get here:
jarektkaczyk / laravel-multiformat-response.php
Last active Jun 24, 2018
laravel multiformat response
View laravel-multiformat-response.php
Response::macro('multiFormat', function ($data, $html = '') {
if (request('format') == 'json') {
return $this->json($data);
if (request('format') == 'xml') {
if (!is_array($data) && !$data instanceof Arrayable) { /* 400 Bad Request*/ }
You can’t perform that action at this time.