Skip to content

Instantly share code, notes, and snippets.

View rogercbe's full-sized avatar

Roger Cendrós rogercbe

View GitHub Profile
@rogercbe
rogercbe / Sortable.php
Last active February 9, 2022 16:26
Sortable trait for sorting tables with relationships in Laravel with a table helper class for displaying the links as an extension of the Laravel Paginator
<?php
namespace App\Support;
use Illuminate\Database\Eloquent\Relations\HasOne;
trait Sortable
{
public function scopeSortable($query, $defaultSort = null, $direction = 'asc')
{
@rogercbe
rogercbe / git-ignore.sh
Created February 2, 2018 17:02 — forked from jeffjohnson9046/git-ignore.sh
Remove unwanted files from a git repo AFTER adding a .gitignore. The files will remain on disk.
## I just ran into this after initializing a Visual Studio project _before_ adding a .gitignore file (like an idiot).
## I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands
## came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
# See the unwanted files:
git ls-files -ci --exclude-standard
# Remove the unwanted files:
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
@rogercbe
rogercbe / .zshrc
Created May 10, 2018 14:45
Composer alias to develop Laravel packages locally
composer-link() {
composer config repositories.local '{"type": "path", "url": "'$1'"}' --file composer.json
}
@rogercbe
rogercbe / Errors.js
Last active May 13, 2018 21:00
Form Object
class Errors {
constructor() {
this.errors = {};
}
get(field) {
if (this.errors[field]) {
return this.errors[field][0];
}
}
@rogercbe
rogercbe / ExampleModel.php
Last active May 14, 2018 12:05
Abstract code generation to a trait
<?php
namespace App;
use App\Support\Traits\GenerateUniqueCode;
use App\Support\Contracts\GeneratesCodes;
use Illuminate\Database\Eloquent\Model;
class Lead extends Model implements GeneratesCodes
{
@rogercbe
rogercbe / ngrok.sh
Created May 14, 2018 14:34
Ngrok command to expose homestead sites
./ngrok http -host-header=rewrite {url}:{port}
# Example
./ngrok http -host-header=rewrite project.test:80
@rogercbe
rogercbe / AppServiceProvider.md
Last active June 4, 2018 13:48
Laravel macro to extend Carbon and generate array of dates in a daterange

Code

public function boot()
{
    Carbon::macro('range', function ($start, $end) {
        return new Collection(
            new DatePeriod(
                $start, 
                new DateInterval('P1D'), 
 $end-&gt;copy()-&gt;add(new DateInterval('P1D'))
<?php
class GlobalSearch
{
protected $searchGroups = [
'Users' => UserSearchGroup::class,
];
protected function searchGroups()
{
@rogercbe
rogercbe / init.sh
Created November 12, 2018 14:46
Starter script
#!/bin/bash
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
npm install
npm run dev