Skip to content

Instantly share code, notes, and snippets.

Patrique Ouimet patoui

Block or report user

Report or block patoui

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View setting-up-ubuntu-16-04-for-laravel-development
## LEMP Stack
First we'll need to install the backend essentials: Nginx, MySQL, PHP (with FPM).
### Nginx
```
sudo apt-get update
sudo apt-get install nginx
```
View sortable-laravel-models-with-a-trait-and-query-scope
## Introduction
This post aims to provide a simple example of how to use traits with Laravel Query Scopes. The trait will sort columns based on "sort" and "direction" being found within the request, while protecting the database of unwanted sorting by adding a "sortables" property to the model. The end result looks like this with a Post model as an example:
```
Post::sort(request())
```
### Sortable trait
View settings-up-windows-subsystem-for-linux-for-laravel-development-lemp
## Introduction
This is a guide on how to get setup with Windows Subsystem for Linux (Ubuntu) for Laravel Development (LEMP). Which gives you the flexibility of the Linux terminal and the application compatibility of Windows.
Recently I decided to switch from Ubuntu 16.04 to Windows 10 Pro as I wanted access to applications that are not available on Linux based operating systems (i.e. Microsoft Office 2016, Adobe Suite). I know there are plenty of alternatives (or things like Play on Linux, Lutris, Crossover), but I wanted to tests on what my customers are using and I got tired of using virtual machines.
All that to say that I’ve got Ubuntu application (Windows Subsystem for Linux) working on Windows 10 Pro, so I didn’t lose any of the power of the Linux terminal but gained all the application compatibility of the Windows 10 operating system.
### Caveats
I’m using the Insider Program builds so my current system looks like:
View gist:fd45f29101b0ca3ea22b536cd44617c9
Find/Replace strip Laravel config for value only
FIND: ^.*=> '(.*)',
REPLACE: $1
@patoui
patoui / setting-up-webpack-in-ruby-on-rails.md
Last active Nov 21, 2018
Setting Up Webpack in Ruby on Rails
View setting-up-webpack-in-ruby-on-rails.md

Introduction

This is a simple introduction on how I setup Webpack in Ruby on Rails. I hope it'll be useful to others who wanted to use Webpack within a Rails application like I did.

Caveats

This article assumes you've already setup a rails project via rails new {project-name}

Setting Up Sprockets

@patoui
patoui / ruby-on-rails-exploration-part-1.md
Created Nov 25, 2018
ruby-on-rails-exploration-part-1
View ruby-on-rails-exploration-part-1.md

Introduction

This is an overview of things I've learnt while working on my side project anonforum in Ruby on Rails.

Today's topics:

  • Testing (models and controllers)
  • Routing
  • Controllers
  • Views (helpers)
@patoui
patoui / ruby-on-rails-exploration-part-2.md
Last active Dec 5, 2018
ruby-on-rails-exploration-part-2
View ruby-on-rails-exploration-part-2.md

Introduction

Part 2! This is an overview of things I've learnt while working on my side project Anon Forum in Ruby on Rails.

Today's topics:

  • Custom Validation
  • Pagination

Custom Validation

@patoui
patoui / namespace-before-action-sample.rb
Created Dec 8, 2018
Applying before_action to entire namespace sample
View namespace-before-action-sample.rb
# config/routes.rb
namespace :admin do
get 'dashboard' => 'dashboard#index'
end
# app/controllers/admin/admin_controller.rb
include SessionsHelper
class Admin::AdminController < ApplicationController
http_basic_authenticate_with name: "johndoe", password: "secret"
View laravel-eloquent-vs-collection-count.md

Laravel Eloquent vs Collection Count

This can be a little confusing as the syntax barely changes but it makes a big difference.

Using Collection "count"

This seems harmless, but I'll explain why it can be bad for performance

$post->comments->count();
@patoui
patoui / HasManyUpdator.php
Last active Sep 26, 2019
Utility class to perform multiple updates on a has many relationship (thanks to Glen UK on Larachat for finding bugs)
View HasManyUpdator.php
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\RelationNotFoundException;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class HasManyUpdater
You can’t perform that action at this time.