Warning: The magic method SFML_Singleton::__wakeup() must have public visibility in /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php on line 72
code – Thoughts, etc.

Thoughts, etc.

Tracking the occasional random walk

code

JSON responses as PHP arrays in Laravel 8 tests

2021-02-10 / Leave a Comment

I’m in the process of upgrading an API code base that has been in production since Laravel 5, and continues to evolve. The bulk of the update to version 8 went smoothly, but one breaking change that I couldn’t find documented anywhere held me up for some time this afternoon. A great many of the … [Read more…]

Posted in: code Tagged: laravel

Side effects of js-data-http and async operations

2018-06-15 / Leave a Comment

Recently I encountered a rather strange scenario, wherein I created two different  findAll operations using the js-data-http adapter for a js-data query, only to see two identical network requests emitted. The root of the problem turned out to be that I was creating a single object to hold the query options and reusing it across requests, in … [Read more…]

Posted in: code, front-end Tagged: js-data

Adding Vue reactivity to js-data relationships

2018-05-16 / 3 Comments

While attempting to have Vue components react to changes in my js-data model instances and their relationships, I found a great post from Caleb Roseland with an accompanying code example. They detail how to make model properties reactive in Vue, without overriding js-data’s own reactivity. What they don’t discuss is how to make Vue react … [Read more…]

Posted in: front-end Tagged: js-data, vue

Getting a Faker instance in Laravel’s tinker environment

2018-05-03 / 3 Comments

I sometimes find that it would be useful to use  artisan tinker to play with the sorts of data that Faker will generate in a Laravel factory. Unfortunately I don’t do it often enough to always remember the correct way to do it, since the obvious  new Faker\Generator doesn’t work. So for future reference, what you need is:

1
>>> $faker = Faker\Factory::create();

 

Posted in: snippets Tagged: laravel, notes

What to do if js-data serializes array elements as empty objects

2018-04-30 / Leave a Comment

TL;DR: Use the items validation keyword to specify the data type of the elements of arrays in your js-data schema to avoid unexpected results when serializing records, e.g. for saving. The setup I was using js-data v3 with a schema containing an array field recently, and came across some initially baffling behaviour. I had a fooSchema … [Read more…]

Posted in: code Tagged: js-data

Clearing an Ember Paper select component

2017-09-01 / Leave a Comment

To allow users to clear the selection of an Ember Paper {{paper-select}} component, simply pass it the  allowClear=true option:

Allowing a paper-select component to be cleared
1
2
3
4
5
6
{{#paper-select
    placeholder="Select a thing..."
    required=false
    allowClear=true
    ...
}}

This option is passed along to the ember-power-select component that ember-paper uses under the hood, so the resulting clear button can be styled accordingly. For example,

Styling the clear-selection button
Sass
1
2
3
4
.ember-power-select-clear-btn {
  position: absolute;
  right: 25px;
}

Thanks to @miguelcobain for this tip on the community Slack channel.

Posted in: front-end Tagged: ember, ember-paper

Primary keys other than “id” in lumen-jwt

2017-06-20 / Leave a Comment

Lumen-jwt is a great library that easily adds JavaScript Web Token (JWT) authentication to any Lumen application. I recently had the opportunity to submit my second pull request to the project, allowing user accounts to be uniquely identified via fields other than id, which was previously the only option. (As of this writing the PR has been … [Read more…]

Posted in: code Tagged: jwt, lumen, php

Many-to-many relationships in Ember CLI Mirage factories

2017-03-27 / 1 Comment

The many-to-many example provided with the introduction of Mirage 0.3 lays out how to create many-to-many joins between specific instances of two models. It does this by hard coding the creation of a few books and a couple of authors, as well as the links between them, but stops short of using factories to generate such relationships … [Read more…]

Posted in: code Tagged: ember

Responding to HTTP OPTIONS requests in CakePHP

2017-02-28 / 4 Comments

I recently needed to add  Access-Control-Allow-Origin headers to resources on an API developed with CakePHP. There’s a good description of how to accomplish this from ThinkingMedia in 2015, but it uses DispatcherFilters, which have since been deprecated in favour of Middleware. The $request  and $response objects available to middleware have different interfaces than those retrieved from the event data in the … [Read more…]

Posted in: code Tagged: cakephp

Abstract app controllers and the CakePHP ACL plugin

2016-12-06 / Leave a Comment

I’m working on a CakePHP-based app that has multiple abstract base controller classes that inherit from AppController. The majority of the concrete controllers inherit from one of these abstract classes. I recently added the CakePHP/Acl plugin to the app, and was presented with the error

Shell
1
Exception: Cannot instantiate abstract class App\Controller\MyAbstractController in [/apppath/vendor/cakephp/acl/src/AclExtras.php, line 433]

when I tried to use the  bin/cake acl_extras aco_sync command to generate ACOs … [Read more…]

Posted in: code Tagged: cakephp
1 2 Next »