Skip to content

Instantly share code, notes, and snippets.

View jeffochoa's full-sized avatar

Jeff Ochoa jeffochoa

View GitHub Profile
@jeffochoa
jeffochoa / Response.php
Last active May 4, 2024 08:50
Laravel HTTP status code
<?php
// This can be found in the Symfony\Component\HttpFoundation\Response class
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
@jeffochoa
jeffochoa / 1.ProcessClass.php
Last active April 23, 2024 21:22
Understanding Laravel pipelines
<?php
namespace App\Features;
use App\Features\FirstTask;
use App\Features\SecondTask;
use Illuminate\Pipeline\Pipeline;
// *Naming things is hard* ... So, this is a class called `ProcessClass` that `run()` some text ¯\_(ツ)_/¯
class ProcessClass
@jeffochoa
jeffochoa / .php_cs
Last active March 11, 2024 20:21 — forked from jannejava/.php_cs
PHPCS Fixer for VSCode and Laravel
<?php
return PhpCsFixer\Config::create()
->setRules(array(
'@PSR2' => true,
'binary_operator_spaces' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'braces' => true,
@jeffochoa
jeffochoa / event.js
Last active April 13, 2023 19:55
VueJs global event dispatcher
class Event {
constructor() {
this.vue = new Vue();
}
fire(event, data = null) {
this.vue.$emit(event, data);
}
listen(event, callback) {
@jeffochoa
jeffochoa / Errors.js
Last active February 9, 2022 09:52
Vue Form and Error validator (Laracasts)
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
@jeffochoa
jeffochoa / EloquentSortableServiceProvider.php
Last active June 9, 2021 01:33
Laravel Eloquent pagination and column sorting using macros
<?php
namespace App\Providers;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\ServiceProvider;
class EloquentSortableServiceProvider extends ServiceProvider
{
@jeffochoa
jeffochoa / UploadMediaToWp.php
Last active January 3, 2020 13:39 — forked from s-hiroshi/WP API v2 image upload from media endpoint
WP API v2 image upload from media endpoint
<?php
/*
* WP REST API version 2.0-beta7
* API base url ishttp://www.example.com/wp-json
*
* Reference
* https://wordpress.org/support/topic/new-post-with-image
*/
/*
@jeffochoa
jeffochoa / ProgressBarCallback.php
Last active May 28, 2019 16:10
ProgressBar callback trait for Laravel commands
<?php
namespace App\commands;
trait ProgressionBarOutput
{
public function runProcess(\Countable $countable, callable $callback)
{
$bar = $this->output->createProgressBar(count($countable));
$bar->start();
@jeffochoa
jeffochoa / autocomplete.php
Last active May 28, 2019 10:23 — forked from imranismail/autocomplete.php
Input autocomplete Laravel + Javascript
//SearchController.php
public function autocomplete(){
$term = Input::get('term');
$results = array();
$queries = DB::table('users')
->where('first_name', 'LIKE', '%'.$term.'%')
->orWhere('last_name', 'LIKE', '%'.$term.'%')
->take(5)->get();
@jeffochoa
jeffochoa / RouterServiceProvider.php
Created July 30, 2017 20:28
Get collection of available routes in Laravel
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Route as Router;
class RouterServiceProvider extends ServiceProvider
{