Skip to content

Instantly share code, notes, and snippets.

View jeffochoa's full-sized avatar

Jeff Ochoa jeffochoa

View GitHub Profile
@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
{
@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 / OwnsModelTrait.php
Last active November 19, 2018 06:07
Laravel OwnsModel Trait
<?php
trait OwnsModel {
/**
* Determine whether this model owns the given model.
* Usage: if ($user->owns($article)) { ...
*
* @param Model $model
* @return bool
@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 / laravel.js
Created February 24, 2016 12:36 — forked from JeffreyWay/laravel.js
Want to send a DELETE request when outside of a form? This will handle the form-creation bits for you dynamically, similar to the Rails implementation. (Requires jQuery, but doesn't have to.) To use, import script, and create a link with the `data-method="DELETE"` attribute.
/*
<a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request
- Or, request confirmation in the process -
<a href="posts/2" data-method="delete" data-confirm="Are you sure?">
*/
(function() {
@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();