Skip to content

Instantly share code, notes, and snippets.

View jgrossi's full-sized avatar
👨‍💻
probably writing code

Junior Grossi jgrossi

👨‍💻
probably writing code
View GitHub Profile
@jgrossi
jgrossi / AttachJwtToken.php
Last active August 14, 2021 18:14
AttachJwtToken.php
<?php
namespace Tests\Concerns;
use App\Models\User;
use Tymon\JWTAuth\Facades\JWTAuth;
trait AttachJwtToken
{
/**
@jgrossi
jgrossi / QueryFilter.php
Last active July 14, 2017 10:09
Model Filtering according the URL
<?php
namespace App\Filters;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
abstract class QueryFilter
{
/**
@jgrossi
jgrossi / phpver
Last active August 4, 2017 12:24
PHP command to switch PHP versions using Homebrew
#!/usr/bin/php
<?php
if (!isset($argv[1])) {
echo_error("Please, tell me what PHP version you want!");
exit;
}
$to_version = $argv[1];
$to_version = (int)str_replace('.', '', $to_version);
@jgrossi
jgrossi / Post.php
Last active February 23, 2016 18:30
How to use different connections with Corcel
<?php
// set your model file and tell it the connection name you're using in config/database.php
// file: app/Post.php
namespace App;
use Corcel\Post as Corcel;
class Post extends Corcel
@jgrossi
jgrossi / Service.php
Created February 22, 2016 16:09
Custom post types and models
<?php
use Corcel\Post as Corcel;
class Service extends Corcel
{
protected $postType = 'service';
}
@jgrossi
jgrossi / example.php
Created February 22, 2016 16:06
Get post custom fields
<?php
$post = Post::find(1);
$avatar = $post->meta->avatar;
$phone = $post->meta->phone;
@jgrossi
jgrossi / AnyController.php
Created February 19, 2016 21:09
Fetch posts and page details from a Laravel controller using Corcel
<?php // File: /app/Http/Controllers/AnyController.php
// ...
public function index()
{
$posts = Post::published()->take(10)->get();
$page = Page::where('post_name', 'about')->first();
return view('posts.index', compact('posts', 'page'));
@jgrossi
jgrossi / database.php
Created February 19, 2016 21:01
Laravel and Wordpress together
<?php // File: /config/database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'app',
'username' => 'admin'
'password' => 'secret',
@jgrossi
jgrossi / Car.php
Last active March 19, 2024 11:05
How to use Eloquent (from Laravel) inside Wordpress
<?php // File location: /wp-content/themes/my-theme/src/Models/
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Car extends Eloquent
{
protected $table = 'cars';
protected $primaryId = 'id';
Verifying that +jgrossi is my blockchain ID. https://onename.com/jgrossi