Skip to content

Instantly share code, notes, and snippets.

View brayniverse's full-sized avatar

Christopher L Bray brayniverse

View GitHub Profile
@brayniverse
brayniverse / machine.js
Last active February 6, 2020 15:59
Generated by XState Viz: https://xstate.js.org/viz
const editStates = {
initial: 'saved',
states: {
open: {
on: {
SAVE: 'saved'
}
},
saved: {
on: {
@brayniverse
brayniverse / Post.php
Last active December 12, 2018 22:12
Custom Eloquent query builders
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Create a new Eloquent query builder for the model.

This is in response to Matt Stauffer's blog post Form array validation in Laravel 5.2.

At the end Matt explains that you can apply validation rules to a specific array index, he also says that he is "Not sure why you would do this, but, it's possible".

One scenario I have thought of is when you need to require at least one value for a multiple value field, for example a user can have many email addresses.

$this->validate($request->all(), [
  'email_addresses.1' => 'required|email',
 'email_addresses.2' =&gt; 'email',