Skip to content

Mastering PHP and Laravel

Never stop learning!

Menu

  • Home
  • Blog Posts
  • Humor

Programming

The Pipeline Pattern

The pipeline pattern is one way to refactor your code to separate concerns. Here is an example of un-refactored code that uses individual if statements to process some data. I’ll keep the details out for clarity. This code seems simple

Kenny July 3, 2023September 27, 2023 Learning, PHP Read more

MySQL Explain Type Column

I copied the following here for my convenience. Original source: https://www.taogenjia.com/2020/06/08/mysql-explain/ The type Column The MySQL manual says this column shows the “join type”, but it’s more accurate to say the access type. In other words, how MySQL has decided

Kenny March 16, 2023September 27, 2023 MySQL Read more

How to quickly toggle xdebug

When running unit tests, xdebug will slow things down quite a bit. Most of the time we run tests we don’t need xdebug because we are not doing code coverage, or actually debugging. Here is how I quickly toggle xdebug

Kenny January 12, 2023September 27, 2023 Blog Posts, Mac Terminal / Linux, Programming Read more

The current state of things

It’s amazing how life gets going in a rhythm, and you get your head down and working so hard, that you sometimes forget to look around (or in this case, write in your blog). Working at a small travel advertising

Kenny March 26, 2020September 27, 2023 Blog Posts, Javascript, Laravel, Learning, PHP, Programming Read more

Sorting Associative Arrays in PHP

$arr = [ ‘foo’ => ‘bar’, ‘faz’ => ‘baz’ ]; array_multisort(array_column($arr, ‘value’), SORT_ASC, $arr); You can sort an associative array with one line of code as I did above. As a result, the array becomes sorted by the keys: [

Kenny January 6, 2020September 27, 2023 Blog Posts, Learning, PHP, Programming Read more

PHPStorm – Stop those accidental tab closures!

If you’re like me, you have probably had this happen. You go to click on one of the many tabs you have open in PHPStorm, only to accidentally click the X, and close it. ARGH! Today I found a way

Kenny October 9, 2019September 27, 2023 Blog Posts, PHP, PHP Storm, Programming, Tools Read more

Defensive Programming | Laravel find()

Defensive Programming One of the things I’ve learned in my career is to code defensively. Laravel makes it very easy to ask for an object, but it also makes it very easy to get it wrong. If you request an

Kenny February 5, 2019September 27, 2023 Blog Posts, Eloquent, Laravel, PHP Read more

Some resources

Here are some great resources I found recently. Unsplash Free Stock Photos Remove.bg Remove background from portraits Page Cache Whole page caching IsoRepublic.com Free hi-res photos and videos

Kenny December 20, 2018September 27, 2023 Blog Posts, Programming Read more

Laravel – the difference between all() and get()

When dealing with a model, all()  is a static method. It creates a new query object, and runs get()  on that object get()  is not static, but can be called statically because of a magic method in the Model class.

Kenny October 12, 2018September 27, 2023 Blog Posts, Eloquent, Laravel, Learning, Programming Read more

Laravel Eloquent only()

$fullModel = Model::find(1) // Get model with id 1 $idArray = $fullModel->only(‘id’) // array containing id // this does not work. You’ll get back an empty collection // It is trying to pull the id column off the collection object,

Kenny October 12, 2018September 27, 2023 Blog Posts, Eloquent, Laravel, Learning, Programming Read more

MySQL Stored Procedures

Here is a tip you can use when writing a stored procedure, and using prepared statements. Since you have to pass the statements in through EXECUTE stmt USING …   it can get confusing if there are a large number of

Kenny October 11, 2018September 27, 2023 Blog Posts, Learning, MySQL, Programming Read more

Laravel Eloquent Attributes

When dealing with an Eloquent model, you can add your own attributes. These can be useful for computed values. For example: class Person extends Model { // By default, all the database fields will be available. // Let’s assume for

Kenny October 9, 2018September 27, 2023 Blog Posts, Laravel, Learning, PHP, Programming Read more

Laravel Eloquent sortBy function

Here is how you can sort a collection by an ordered array of ids. The use case here was that I had a number of objects in a Redis cache, which were retrieved in unsorted order. The objects were large,

Kenny October 9, 2018September 27, 2023 Blog Posts, Laravel, PHP, Programming Read more

SQL EXPLAIN: The “Extra” column

This column contains additional information about how MySql resolved the query. There is a line in the manual which states: If you want to make your queries as fast as possible, look out for Extra values of Using filesort and Using temporary. Let’s examine why

Kenny September 25, 2018September 27, 2023 Blog Posts, Learning, MySQL, Programming Read more

SQL EXPLAIN: The “filtered” column

The filtered column shows an estimated percentage of rows that will be filtered by the table WHERE clause. It’s typically only shown during the EXPLAIN EXTENDED command.

Kenny September 25, 2018September 27, 2023 Blog Posts, Learning, Programming, SQL Read more

SQL EXPLAIN: The “ref” column

The “ref” column shows which columns or constants are compared to the index named in the “key” column to select rows from the table. This comes right from the manual, but I have noticed that when the value is const,

Kenny September 25, 2018September 27, 2023 Blog Posts, Learning, Programming, SQL Read more

SQL EXPLAIN: Index-related columns

These relate to the usage of indexes:  possible_keys Which indexes were considered? key Which indexes did the optimizer choose?  key_len How many bytes of the index will be used?

Kenny September 25, 2018September 27, 2023 Blog Posts, Learning, Programming, SQL Read more

SQL EXPLAIN: The “type” column

The “type” column indicates how MySQL will access rows From worse to better: ALL index range ref eq_ref const system NULL

Kenny September 25, 2018September 27, 2023 Blog Posts, Learning, Programming, SQL Read more

A faster alternative to correlated sub-queries

I recently had to rewrite a query that was running very slowly. It was taking over 30 seconds. Upon analyzing it, I saw that it had 2 correlated sub-queries in it, and each was doing a count(*). This meant that

Kenny September 19, 2018September 27, 2023 Blog Posts, Learning, Programming, SQL Read more

You might not need jQuery…

I just found a video that talks about how jQuery is no longer needed in 2018. I found it interesting, and thought I’d save it and some related pages here for future reference. http://microjs.com/#ajax https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch https://caniuse.com http://youmightnotneedjquery.com/

Kenny September 5, 2018September 27, 2023 Blog Posts, Javascript, Learning, Programming Read more
  • « Previous

Archives

Categories

Copyright © 2025 Mastering PHP and Laravel. All rights reserved. Theme Spacious by ThemeGrill. Powered by: WordPress.