allenjd3 a place to set on

Laravel Invalid Parameter Number with whereIn()

I’m posting this so that I remember in a few years when this happens again…

We had a very interesting error that simply said- SQLSTATE[HY093]: Invalid parameter number. The query that it showed looked fine and so I spent a significant amount of time scratching my head wondering if I was losing my marbles.

Here was the query-

select * from posts where uuid in (random-uuid-here)

Looks fine right? Well turns out we were passing an array of an array into this whereIn- something that looked similar to this-

[
  [
    'uuid_1',
    'uuid_2',
    'uuid_3',
  ]
]

And this generated a query that looked like this-

select * from posts where uuid in (?)

It was attempting to bind each uuid to that one parameter so it gave the invalid parameter number error. What we needed was something closer to this-

select * from posts where uuid in (?, ?, ?)

The solution was to flatten the array down to a single depth so whereIn would know to bind the correct number of parameters.

Future me- if you ever read this, make sure you pass flat arrays into whereIn. Pretty please?

WP Mail SMTP Goodness

I recently migrated a wordpress site that I manage to trellis. Trellis is a deployment tool which makes deploying wordpress sites a breeze. Its fairly opinionated about how everything works however so I wasn’t sure how it would go. Here are my initial thoughts-

Wow it was easy to set up!

Rebuilding the site which used to take an entire afternoon took me about 30 minutes with trellis. Basically all I had was a fresh ubuntu instance on Digital Ocean, my sql dump file from my previous page and the contents of the wp contents folder. Trellis set up everything really quickly and its more secure than I could ever make it.

Hmm- something is weird here…

I immediately started noticing odd issues with wordfence. I uninstalled the plugin and reinstalled- all started working again. Then I started to get fatal errors blamed on yoast seo. I disabled the plugin and everything was working again.

Yoast didn’t like wp smtp

In my efforts to figure out why yoast wasn’t working correctly I discovered that if I disabled WP SMTP then yoast would stop killing my post editing. Then I noticed something odd. Apparently when I migrated the site, WP SMTP didn’t have all of its database tables that it needed. My simple solution: uninstall and reinstall. I was hoping for a quick solution like with wordfence but in this case, reinstalling did nothing.

Long story short, I found a setting that allowed me to delete all data from WP SMTP from the database. It was in the miscellaneous tab of the WP SMTP settings.

Screen Shot 2022-03-30 at 9 44 01 AM

After I checked that box- I just uninstalled and reinstalled the plugin. The only downside was having to find my mailgun key again but that wasn’t a huge deal. WP SMTP installed all its necessary tables and we are back in business

Overall, I love trellis. It is ten times quicker to make changes to the site and if something were to happen to my current site it wouldn’t take long to completely rebuild it elsewhere. I give it two thumbs and two big toes up.

Thinking in React... in Livewire

So I’ve talked a little about Hotwire in the past but for Laravel there is a much more ubiquitous “wire” around- Livewire. Hotwire is very much a “build the way you always build and then sprinkle in the magic” tool. Livewire is more of a thought switch so I struggled with it at first. I think I’ve found the correct balance for it though and it comes from an article I read in the React Docs of all places: Thinking in React

Livewire is a bit of a mental switch. Its more react-like in the way it handles data. The craziest thing to me is that you don’t need controllers anymore. All the business logic can be organized into components. You can even route to individual components.

Route::get('/post', ShowPosts::class);

The key to thinking livewire is to break your component into smaller components like in the ‘thinking in react’ article linked above. This helps to answer the questions-

  1. What do I test?
  2. Where do I query the data?
  3. Do I pass it as props or do I handle it in the component itself?
  4. Where do I change or act on the data?

Without answering these questions, you can get some really odd spaghetti code. You can be querying and modifying data in a sub component that shouldn’t have that ability. It makes it harder to tell which components are mutating state and which are getting their own state. Start thinking in react in livewire. Seriously- helps a lot.