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
Software Engineering Books
My Book List For 2022 As an Amazon Associate, I earn from qualifying purchases. This page contains affiliate links. If you choose to purchase after clicking a link, I may receive a commission at no extra cost to you. These
PHPStorm Shortcuts For Mac
Here are some great keyboard shortcuts I have set up to help you become more efficient in PHPStorm!
Inject Storage in Laravel
How do you inject Storage in Laravel? I’ve noticed in my Google searches that all the examples I come across on how to use the various components of Laravel only show how to use Facades. But what if you want
PHP 8 Named Arguments
In PHP 8, you can use named arguments, which allows you to provide the parameters of a function in any order: PHP 7.x PHP 8 Even if you choose not to reorder the params, it will make the code clearer
A fast way to reformat code in PHPStorm
Today I found a way to do a regex find that makes reformatting code easy. Let’s say we have some code like this: and you want it formatted like this: This is what I prefer because it gives more breathing
pushd / popd
I learned a great Linux command today! I find myself jumping between my web directory and the apache config directory occasionally on my server, and by using pushd from the web directory, I’ll now be able to quickly return to
Pipelines
Have you heard of the pipeline pattern? The pipeline pattern is used by Laravel internally, and is a really nice way to clean up your code. I found a video that explains it well. I watched yesterday, then today I
Keeping busy during trying times
Having so much time off as I have lately, I’ve been taking the opportunity to clean up my online digital world a bit. Things like creating headers for all the social accounts tied to our Basenji Adventures brand, and creating
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
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: [
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
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
WordPress permalinks not working
WordPress permalinks not working? I feel your pain. Read on… Recently, after setting up another virtual host on my Linux server, for a WordPress site, permalinks were not working. Any page other than home was getting a 404 error. I
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
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.
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,
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
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
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,