Skip to content

Instantly share code, notes, and snippets.

@tlkshadow
tlkshadow / bad-example.sql
Last active April 24, 2017 07:42
Bad example
SELECT 
 a.id
 b.name,
 s.name,
 s.address,
 max(ap.price) as newest_price,
 wm.quantity
 #— ….
FROM article a 
JOIN brand b on a.brand_id = b.id
SELECT
a.id,
(SELECT name FROM brand WHERE id = a.brand_id) as name,
(SELECT group_concat(name) FROM supplier WHERE s.article_id = a.id) as supplier_names,
(SELECT max(price) FROM article_price WHERE article_id = a.id) as max_price
FROM article a
{
"data": [{
"variable_1": 100001,
"variable_2": "Variable name",
"variable_3": "Variable name 2",
"variable_4": "2017–01–01",
"variable_5": [
"value 1",
"value 2"
],
{
"data": [{
"a": 100001,
"b": "Variable name",
"c": "Variable name 2",
"d": "2017–01–01",
"e": [
"value 1",
"value 2" 
],
@tlkshadow
tlkshadow / SetDynamicDatabaseConnection.php
Created December 17, 2017 20:42
SetDynamicDatabaseConnection.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
/**
* @author Marcel Domke <marcel.domke@aboutyou.de>
<?php
View::composer('profile', function ($view) {
$view->with('user', ['...']);
});
// OR
View::composer('profile', 'App\Http\ViewComposers\ProfileComposer');
@tlkshadow
tlkshadow / view-composer-parameters.php
Last active November 30, 2018 08:08
view-composer-parameters.php
<?php
// append the composer only to one profile: ~/resources/views/profile
View::composer('profile', ...);
// to serveral: ~/resources/views/profile, ~/resources/views/profile_edit and ~/resources/views/profile_settings
View::composer(['profile', 'profile_edit', 'profile_settings'], ...);
// wildcard folders: all files in ~/resources/views/pages/*
View::composer(['*pages.*'], ...);
<?php
View::composer('*', function ($view) {
$view->with('breadcrumb', ['item 1', 'item ']);
});
// or
View::composer('*', 'App\Http\ViewComposers\NavigationComposer');
@tlkshadow
tlkshadow / Medium-ViewComposerTest.php
Last active December 2, 2018 12:17
Medium-ViewComposerTest.php
<?php
class ViewComposerTest extends TestCase
{
/**
* @return void
*/
public function testDetailHasNavigationItems()
{
$this->get('/detail')->assertViewHas('navigation');
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewComposerServiceProvider extends ServiceProvider
{