Skip to content

Instantly share code, notes, and snippets.

@tonysm
tonysm / option-1.php
Last active April 10, 2019 14:45
API resource eager loading, simplified
<?php
class OrganisationUserGroupsController
{
public function index(ListOrganisationUserGroupsRequest $request, Organisation $organisation)
{
$userGroups = $organisation->userGroups()
->applyFilters($request->filters())
->paginate();
@tonysm
tonysm / option-1.php
Last active April 10, 2019 14:08
Eager loading and JSON transformation
<?php
// In this option, the eager loading is requested by
// the transformer, so it does not rely on the data
// passed to it to handle eager loading prior.
class OrganisationUserGroupsController
{
public function index(
OrganisationUserGroupsIndexRequest $request,
@tonysm
tonysm / readme.md
Last active December 6, 2018 14:04
Laravel Broadcasting Extended

Since we now have a way to deal with WebSockets in PHP/Laravel, I was wondering if we could extend the functionalities of Laravel Echo a bit more than the current API to actually use the bi-directional capabilities of WebSockets.

This gist is a draft of what it would be to use this extension.

Client Side Extension

Right now we can authenticate on private/presence channels. It's also possible to send client-side events in these channels using this API:

const channel = Echo.private(`chatroom.${this.chatroom.id}`);
@tonysm
tonysm / readme.md
Created November 27, 2018 18:58
Laravel and WebRTC

Resources

There is a great tutorial online here

@tonysm
tonysm / readme.md
Created November 26, 2018 14:25
Laravel Echo Server
  1. Follow the introduction here
  2. Try to set it up on Forge (see this issue)
  3. Try to set it up locally using docker
@tonysm
tonysm / 01.sh
Last active October 7, 2018 02:00
$ minikube status
========================================
kubectl could not be found on your path. kubectl is a requirement for using minikube
To install kubectl, please run the following:
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
To disable this message, run the following:
minikube config set WantKubectlDownloadMsg false
<?php
class Test
{
public function testUserCanSendMessagesToTheirCurrent()
{
Broadcast::shouldReceive('event')->once()->andReturnSelf();
$user = $this->createUser();
$response = $this->actingAs($user, 'api')
->postJson("/api/channels/{$user->current_channel_id}/messages", [
<?php
namespace App\Providers;
use App\Api\ApiResource;
use App\Nova\UserResource;
class ApiResourcesServiceProvider extends ServiceProvider
{
public function boot()
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: slackish-webapp
namespace: slackishapp
spec:
replicas: 3
minReadySeconds: 10
strategy:
type: RollingUpdate
@tonysm
tonysm / default
Last active July 2, 2018 14:11
Nginx Proxy for Mailcatcher
# Place this outside the server {}
# Mailcatcher Websockets upgrade
# As suggested in http://nginx.org/en/docs/http/websocket.html
map $http_upgrade $connection_upgrade {
default upgrade;
"" close;
}
# Place this inside the server {}, remove any other location block