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 / 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 / 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 / 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 / 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 / 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 / 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 / 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
{
/**