Skip to content

Instantly share code, notes, and snippets.

View adumskis's full-sized avatar

Algirdas Dumskis adumskis

View GitHub Profile
@adumskis
adumskis / AppServiceProvider.php
Created February 22, 2017 13:03
Event listener to prevent empty spaces in sortable list
<?php
namespace App\Providers;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@adumskis
adumskis / PageController.php
Created February 13, 2017 06:21
Unlimited parameters in route
<?php
public function show($slugs_string){
$slugs = explode('/', $slugs_string);
$page = null;
foreach($slugs as $key => $slug){
$page = Page::where('slug', $slug)
->where('parent_id', '=', is_null($page)?null:$page->id)
->firstOrFail();
@adumskis
adumskis / placeholder-fix.js
Created December 5, 2016 11:00
Prevent from placeholder attribute in HTML input submiting as value
$(function() {
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
@adumskis
adumskis / RowNoScope.php
Created November 10, 2016 12:17
Return object with row no in database
<?php
namespace App\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
class RowNoScope implements Scope
@adumskis
adumskis / SortableFixTrait.php
Created July 7, 2016 07:30
For Rutorika\Sortable to fix position field before deleting eloquent
<?php
/**
* For Rutorika\Sortable to fix position field before deleting eloquent
*/
namespace App\Traits;
trait SortableFixTrait
{
@adumskis
adumskis / CustomPageRequest.php
Created November 18, 2015 14:38
Example of Laravel Request to rules by locales
<?php
namespace App\Http\Requests;
use App\CustomPage;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Config;
class CustomPageRequest extends Request
{
@adumskis
adumskis / FillTrait.php
Last active June 3, 2016 06:27
FillTrait for Laravel Traslatable models by fallback locale
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Config;
trait FillTrait {
public static function create(array $attributes = [])
{
$available_locales = Config::get('translatable.locales');
$fallback_locale = Config::get('translatable.fallback_locale');