Skip to content

Instantly share code, notes, and snippets.

View oliuz's full-sized avatar
💻
Coding!

Jose Rosado oliuz

💻
Coding!
View GitHub Profile
// Add this to the "boot()" method of your "AppServiceProvider"
<?php
\Illuminate\Database\Eloquent\Builder::macro('search', function ($name, $search) {
return $this->where($name, 'LIKE', $search ? '%'.$search.'%' : '');
});
@oliuz
oliuz / error_blade_directive.php
Created August 17, 2019 23:59 — forked from calebporzio/error_blade_directive.php
A little Blade directive to make working with validation errors a bit nicer.
<?php
// Usage:
// Before
@if ($errors->has('email'))
<span>{{ $errors->first('email') }}</span>
@endif
// After:
@oliuz
oliuz / time_travel_helper.php
Created August 18, 2019 00:00 — forked from calebporzio/time_travel_helper.php
A little Laravel helper function for hijacking Carbon's "now()" inside a callback
<?php
// Helper usage:
// timeTravel(Carbon::parse('one year ago'), function () {...});
function timeTravel($target, $callback) {
Illuminate\Support\Carbon::setTestNow($target);
return tap($callback(), function () {
Illuminate\Support\Carbon::setTestNow();
@oliuz
oliuz / VueForm.vue
Created August 18, 2019 00:00 — forked from calebporzio/VueForm.vue
A Vue component to include Laravel's CSRF Token within form tag
// Usage:
// <vue-form method="PUT">
// <input type="text" name="email">
// <input type="submit">
// </vue-form>
<template>
<form :method="method.toUpperCase() == 'GET' ? 'GET' : 'POST'">
<input-hidden :value="csrfToken" name="_token"/>
@oliuz
oliuz / InputHidden.vue
Created August 18, 2019 00:00 — forked from calebporzio/InputHidden.vue
A Vue component for turning json into hidden input elements
// Usage:
// <input-hidden name="users" :value="[{name: 'Caleb'}, {name: 'Daniel'}]"/>
// (value can be a: string, integer, array, object)
//
// will render:
// <input class="hidden" type="text" name="users[0][name]" value="Caleb">
// <input class="hidden" type="text" name="users[1][name]" value="Daniel">
<script>
<?php
Blade::directive('route', function ($expression) {
return '<?php route(' . $expression . '); ?>';
});
@oliuz
oliuz / HasUuid.php
Created August 18, 2019 00:02 — forked from calebporzio/HasUuid.php
A little trait to add to models that will have Uuids
<?php
// Example usage in a model:
class ExampleModel extends Model
{
use HasUuid;
protected $primaryKey = 'uuid';
@oliuz
oliuz / ddValidation.php
Created August 18, 2019 00:04 — forked from calebporzio/ddValidation.php
little Laravel TestCase helper to get better validation output
<?php
// Place this method somewhere in TestCase.php
protected function ddValidation(array $except = [])
{
if ($this->originalExceptionHandler == null) {
$this->originalExceptionHandler = app(ExceptionHandler::class);
}
@oliuz
oliuz / HiddenInput.vue
Created August 18, 2019 00:04 — forked from calebporzio/HiddenInput.vue
Little Vue component for turning JSON into native HTML for inputs
<script>
import _ from 'lodash'
export default {
props: [ 'name', 'value' ],
methods: {
flatInputsFromDeepJson(item, key, h) {
if (typeof item === 'object') {
return _.flatMapDeep(item, (value, newKey) => {
@oliuz
oliuz / ex.blade.php
Created August 18, 2019 00:06 — forked from JeffreyWay/ex.blade.php
Blade Directive for SVG Icon.
<!-- Before -->
<svg class="icon is-active" xmlns="http://www.w3.org/2000/svg" width="12" height="16" viewBox="0 0 12 16">
<path d="M5.05.31c.81 2.17.41 3.38-.52 4.31C3.55 5.67 1.98 6.45.9 7.98c-1.45 2.05-1.7 6.53 3.53 7.7-2.2-1.16-2.67-4.52-.3-6.61-.61 2.03.53 3.33 1.94 2.86 1.39-.47 2.3.53 2.27 1.67-.02.78-.31 1.44-1.13 1.81 3.42-.59 4.78-3.42 4.78-5.56 0-2.84-2.53-3.22-1.25-5.61-1.52.13-2.03 1.13-1.89 2.75.09 1.08-1.02 1.8-1.86 1.33-.67-.41-.66-1.19-.06-1.78C8.18 5.31 8.68 2.45 5.05.32L5.03.3l.02.01z"/>
</svg>
<!-- After -->
@icon ('flame', 'is-success')