Skip to content

Instantly share code, notes, and snippets.

View rfmeier's full-sized avatar
💭
Nada.

Ryan Meier rfmeier

💭
Nada.
View GitHub Profile
@rfmeier
rfmeier / response.json
Created April 28, 2022 17:50
Successful formatted response
{
"success": true,
"data": {
"show_in_rest": true,
"show_in_graphql": true,
"singular": "Person",
"plural": "Persons",
"slug": "person",
"api_visibility": "private",
"model_icon": "dashicons-admin-post",
@rfmeier
rfmeier / helper.php
Created April 28, 2022 17:46
Example response helper function
<?php
/**
* Create a WP_REST_Response that uses ACM response data formatting.
*
* @param bool $success Whether the response was successful or not.
* @param array $data The data for the response.
* @param int $status Optional http status code. Default 200.
* @param array $headers Optional http headers. Default empty array.
*
@rfmeier
rfmeier / response-format.json
Created April 27, 2022 21:02
Proposed response format
{
"success": true,
"data": {
"name": "John Doe",
"username": "johndoe123"
}
}
@rfmeier
rfmeier / response.json
Created April 27, 2022 20:59
Formatted response for WP_Error
{
"success": false,
"data": {
"name": [
"Name is required",
"A second Name error message",
"A third Name error message"
],
"email": [
"Email is required"
@rfmeier
rfmeier / response.json
Created April 27, 2022 20:56
WP REST json response for a WP_Error
{
"code": "name",
"message": "Name is required",
"data": {
"status": 400
},
"additional_data": [
{
"status": 400
}
@rfmeier
rfmeier / keybase.md
Created August 20, 2018 14:19
keybase.md

Keybase proof

I hereby claim:

  • I am rfmeier on github.
  • I am rfmeier_wpe (https://keybase.io/rfmeier_wpe) on keybase.
  • I have a public key ASCjN3SgSBVet3Pu16VseFbv2e8-rjZDA4NR-T-eG9iQvAo

To claim this, I am signing this object:

@rfmeier
rfmeier / Controller.php
Created June 7, 2018 01:17
Throw a validation exception from a controller.
<?php
/**
* Throw a ValidationException from within a Controller.
*/
use Illuminate\Validation\ValidationException;
throw ValidationException::withMessages([
'form_item_name' => ['Form item error message.'],
]);
@rfmeier
rfmeier / example.php
Last active December 19, 2017 05:02
Get the current User in Laravel
<?php
$is_authenticated = Auth::check();
$is_guest = Auth::guest();
// Using Auth facade
$user = Auth::user();
// Using auth() helper
$user = auth()->user();
@rfmeier
rfmeier / example.sh
Created November 7, 2017 17:46
Laravel artisan to create a ProductUpdateRequest.
$ php artisan make:request ProductUpdateRequest
@rfmeier
rfmeier / update-example.php
Created November 7, 2017 17:45
Simple controller model update in Laravel.
<?php
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Product $product
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)