Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
probably writing code

Junior Grossi jgrossi

👨‍💻
probably writing code
View GitHub Profile
@jgrossi
jgrossi / AttachJwtToken.php
Last active Aug 14, 2021
AttachJwtToken.php
View AttachJwtToken.php
<?php
namespace Tests\Concerns;
use App\Models\User;
use Tymon\JWTAuth\Facades\JWTAuth;
trait AttachJwtToken
{
/**
@jgrossi
jgrossi / QueryFilter.php
Last active Jul 14, 2017
Model Filtering according the URL
View QueryFilter.php
<?php
namespace App\Filters;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
abstract class QueryFilter
{
/**
@jgrossi
jgrossi / phpver
Last active Aug 4, 2017
PHP command to switch PHP versions using Homebrew
View phpver
#!/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 Feb 23, 2016
How to use different connections with Corcel
View Post.php
<?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 Feb 22, 2016
Custom post types and models
View Service.php
<?php
use Corcel\Post as Corcel;
class Service extends Corcel
{
protected $postType = 'service';
}
@jgrossi
jgrossi / example.php
Created Feb 22, 2016
Get post custom fields
View example.php
<?php
$post = Post::find(1);
$avatar = $post->meta->avatar;
$phone = $post->meta->phone;
@jgrossi
jgrossi / AnyController.php
Created Feb 19, 2016
Fetch posts and page details from a Laravel controller using Corcel
View AnyController.php
<?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 Feb 19, 2016
Laravel and Wordpress together
View database.php
<?php // File: /config/database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'app',
'username' => 'admin'
'password' => 'secret',
@jgrossi
jgrossi / Car.php
Last active Apr 30, 2020
How to use Eloquent (from Laravel) inside Wordpress
View Car.php
<?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';
View gist:6c127b588d1af0e1d733
Verifying that +jgrossi is my blockchain ID. https://onename.com/jgrossi