Blog

404 when deleting a model through Livewire

Posted on: 2021-04-06 15:35:43

LiveWire has become a new favorite thing of mine the last few weeks. It scratches the itch that I've had for a long time now: I want some flexibility in the UI to do some very simple AJAX and I want to stay in Blade templates.

Anyway, I had an interesting issue which looked like this:

  1. Open up a page with a Livewire form on it.
  2. Submit the form, causing a new model to be created.
  3. This model now has a delete button: so click on it.
  4. Livewire shows a 404.

After looking at the HTML coming through the wire, I noticed that the relations Livewire was sending, there was something not right.

Livewire sends some meta-data back to the browser related to your component. It does this, probably, so that it can just rehydrate the models on the component without the original context of the request which was originally used to generate the component.

At any rate, the model's ID that I was generating was 0. Something about the model wasn't serializing properly.

Turns out that I hadn't actually set $incrementing = false nor $primaryKey on this model. It... wasn't a standard incrementing model. It's primary key was based on another table and it was only a 0-or-1 to 1 mapping anyway.

Moral of the story: make sure you test the serializability of your models!

Continue reading...

Nerdy Movies I grew up watching

Posted on: 2021-02-06 15:49:27

I was thinking a few nights ago while listening to the Hacker's soundtrack that there were a ton of movies I watched growing while either growing up or while I was in college. Some of these I watched a lot...

Anyway, I wanted to record this here for posterity... don't want to forget them!

  1. War Games (1983) - This is the move that started it all for me. I remember watching this a lot and thinking how cool it was that the protagonist had a computer in his room. This movie has it all: suspense, nerdery, hacking skills, a little romance, and a happy ending. I did a little war-dialing when I was a kid and this movie was what I felt like I was doing. (Rather than making my mom upset because I was calling numbers I shouldn't have.)

  2. Sneakers (1992) - The original hacking movie. It has everything: social engineering, computer hacking, code-breaking... you name it! And it has Robert Redford. What's not to like? My favorite scene is the scene where he bypasses the temperature sensor by walking really slowly.

  3. The Net (1995) - Sandra Bullock was a big teenage heart-throb. Who doesn't like nerdy girls? She is an amazing thriller actress. Speed only came out the year before. This is a staple nerd-flick if there ever was one.

  4. Hackers (1995) - Ah. This is "the" movie that I can remember watching over and over. The thrill of the hack, the "sticking it to" the big guys. Having a commanding knowledge of technology in this age made one feel like a deityβ€”and these guys made it look cool, too.

  5. Mission Impossible (1996) - Not so much a hacker movie but there was a pretty good component to it. The feels when they were on the train and their upload failed.

  6. Pirates of Silicon Vally (1999) - Noah Wyle played Steve Jobs in this made-for-TV docu-drama exploring Apple and Microsoft in the build-up to the 21st centry. I don't remember much about it, other than I watched it a bunch.

  7. Antitrust (2001) - Another thriller. This movie came out while I was in high-school. I really idolized the way this story was played out as I felt like I connected with the main character.

  8. Operation Takedown (2000) - This one was about Kevin Mitnick. We studied his case some in college and I remember watching this once or twice. No matter how careful you are it seems that your sins will always find you out.

  9. Revolution OS (2001) - A documentary about Linux. Nothing special, but I watched it over and over again in college... on my Slackware machine.

(Dis)honorable Mentions

  • Swordfish (2001) - I think I watched more clips of this than ever watching the movie, but it was pretty talked about in college. A brief search should find out why that was the case.

  • Live Free or Die Hard (2007) - Another hacker movie... with violence. Not a bad movie but I don't remember liking this one much at all.

Did you have a movie that was formative in your life?

Continue reading...

Carbon today() vs. now()

Posted on: 2021-01-13 08:43:55

Beware of Carbon::today() vs. Carbon::now(). They are not synonyms. The former is equiv. to Carbon::now()->startOfDay().

This is important, especially in test environments. If you're thinking that Carbon::today() is actually today... well I suppose it is, but in what timezone?

I had a test that was doing something calculated off of Carbon::today()->subDays(1) and that is not equal to Carbon::now()->subDays(1).

Continue reading...

Notes on using SQLite with Laravel from a MySQL user

Posted on: 2020-12-04 22:44:32

Come with me on a journey to discover how easy (or not) it is to get a large Laravel app working with SQLite.

Continue reading...

Using a CSS Inliner with Laravel

Posted on: 2020-11-29 09:23:15

Here are some notes from my use of the Laravel CSS Inliner plugin. Mainly stemming from problems we had with the responsive CSS getting blown away by the inliner.

Continue reading...

Ah, a blog again.

Posted on: 2018-06-12 19:13:43

I rebuilt this blog in Laravel 5 about 2 years ago as an experiment. Never launched it.

Now I have things to say, so here it comes again.

Continue reading...

Notes on setting up Lockr on Acquia Dev Desktop

Posted on: 2017-09-01 11:01:14

Have been playing around with Lockr on Drupal 7 and want to play around with it locally and so I fall back to Acquia Dev Desktop.

Just as a note, as of the writing of this blog post, Acquia Dev Desktop ships with an invalid openssl.cnf location, so you have to provide one.

I found this out when I started getting this message while trying to create a certificate locally:

RuntimeException: Could not create private key. in Lockr\SiteClient->createCert() (line 37 of /Users/nvahalik/tmp/lockr/src/Lockr/SiteClient.php).

Bummer. Anyway. The fix is simple. Just add the following to your settings.php or local.settings.php (if you're on a Mac):

putenv("OPENSSL_CONF=/private/etc/ssl/openssl.cnf");

And if you're using Lockr, make sure this patch is applied. The patch is needed due to this bug in PHP.

Once you've done that you should be ready to lock and roll!

Continue reading...

An open letter to Dries: What are our values?

Posted on: 2017-03-30 23:57:21

An open letter to Dries Buytaert in response to the happenings with Larry Garfield and the Drupal project's values.

Continue reading...

Yield, Generators, and Iterators in Node.js

Posted on: 2017-03-09 12:57:32

Although I love Drupal, lately some of my projects have had me delve into learning new technologies and Stacks. The one I've spent more time with lately is Node.js.

One reason for this is that I've actually known JavaScript longer than I've known PHP. I started doing JavaScript about 21 years ago... (that feels like a lifetime ago). Anyhoo, I digress.

I tried playing around with Koa last night and it seems really slick. However I was trying to map my mind around this whole yield thing as well as how yield and Generators work together with yield to fundamentally change the way Javascript works.

So it finally dawned on me last night after reading some great articles:

That given this code:

var b = function* () {
  yield 1;
  return 4;
}

let c = b();
console.log(c.next()) // { value: 1, done: false }
console.log(c.next()) // { value: 4, done: true }

That in a sense you could rewrite it as:

var a = function () { return 1; }
var b = function () { return 4; }

console.log(a()) // 1
console.log(b()) // 4

Whenever a yield is encountered, it sort-of slices up the function and returns control back to the caller. The next time .next() is called, the yield expression is resolved and execution picks up where it left off.

Just had to write some thoughts down so I could process them.

Continue reading...

Perceived value and my favorite mobile game

Posted on: 2017-02-13 09:53:02

A few weeks ago I started playing Hill Climb Racing 2. It's a fun, addictive game and, best of all, it's free to play. You actually don't have to spend any money (though you do have to watch ads) but if you're patient, you can unlock everything without paying a single penny!

Recently, I figured I'd splurge and pay $4.99 for one of their little "deals" in the game where you get a deal with a custom decal and a heaping helping of these little things called Gems aka πŸ’Ž.

Now, in the game, you buy vehicle upgrades with coins. You earn coins while driving, doing tricks, going longer and longer distances in the adventure levels, and winning cup races. You also earn 2-5 πŸ’Ž every 6 hours through a "free reward" treasure box and a few more every day or two as you win 10 races by completing and winning cups. Anyway, over the course of a few weeks, you could potentially save a hundred or more gems.

Now gems in the game can only be used for two things: opening treasure boxes (which you get when you win a cup) or purchasing coins. You can't actually purchase coins, but you can purchase gems, which, in turn, can be exchanged for coins.

Now, initially when I did my initial splurge, I opted to "buy" (er, maybe convert) 1000πŸ’Ž into coins. I got 130,000 coin out of the deal. Not bad, I thought to myself. That's 130 coin for every πŸ’Ž.

But then I got to thinking... what would I get if I spent more? Here's the available conversions in the game:

💎CoinsC/💎
10010,000100
20022,000110
50060,000120
1000130,000130
2000280,000140
5000750,000250

Now, I know what you're probably thinking right now... man.. I should really opt for that 5000πŸ’Ž deal where you can get 250C/πŸ’Ž, right? I mean that really is the better deal!

Well, a few moments ago remember I mentioned that you can use πŸ’Ž for 2 things. One is for buying coins, and the other is for unlocking treasure chests. Well, what happens if you only spent your πŸ’Ž unlocking treasure chests? Well...

💎CoinsC/💎
127,000375
2413,000~540
48??
9670,000~730

So with a little patience, it's actually a much better deal to unlock the chests. Sure, it can feel good to get "the best deal" but is it really the best deal? Not really...

Continue reading...