Skip to content

Instantly share code, notes, and snippets.

View pionl's full-sized avatar

Martin Kluska pionl

View GitHub Profile
@pionl
pionl / ModelJoinTrait.php
Last active February 29, 2020 13:08
Model join trait with Automatic Join on Laravel 5 Eloquent Models with relations setup. With automatic filling relation object if detected
<?php
namespace Pion\Traits\Models;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;
/**
* Class ModelJoinTrait
*
* Trait to create model join for scope with detection of model in the attributes.
@pionl
pionl / contentInsetCenter
Created September 4, 2014 09:43
First cell starts in center of the view.
- (CGSize)collectionViewContentSize {
CGSize contentSize = [super collectionViewContentSize];
// we need to center last view
int items = [[self collectionView] numberOfItemsInSection:0];
UICollectionViewLayoutAttributes* layoutAttribute = (UICollectionViewLayoutAttributes*)[super layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:items-1 inSection:0]];
float startX = contentSize.width - self.collectionView.bounds.size.width + self.collectionView.bounds.size.width / 2;
startX = layoutAttribute.frame.origin.x - startX;
@pionl
pionl / NullEmptyStringAttributeTrait.php
Last active May 4, 2016 17:19
Enables the automatic nulling of empty string value. You can provide * list of collumns keys to allow only specified collumns to be nulled. Used in Laravel 5 Model.
<?php
namespace Pion\Traits\Models;
/**
* Class NullEmptyStringAttributeTrait
*
* Enables the automatic nulling of empty string value. You can provide
* list of collumns keys to allow only specified collumns to be nulled.
*
* Usage for setting nullEmptyCollumns:
<?php
namespace Pion\Support;
use Illuminate\Support\Collection;
/**
* Class GroupedCollection
*
* Collection that will support adding values with grouped index (collection indexed by groupKey)
*
@pionl
pionl / RelationCountTrait.php
Created October 21, 2015 19:32
Relation count for Laravel 5 Model with simple usage
<?php
namespace Pion\Traits\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* Trait RelationCountTrait
*
* Usage of where: $count = $model->relationCountWithWhere("user_permission", "user_id", $user, "App\\Models\\User");