" Uncategorised "

Laravel logo

Switching PHP versions automatically with Laravel Valet

Note: This article was originally published by me on SiteRig’s blog on 29th August 2021.

I recently made a contribution to Laravel Valet which adds the ability to specify the PHP version via a .valetphprc file in the project root to make it easier working with the different versions of PHP that some projects may use.

Just make sure you’re using Laravel Valet v2.16.0 or higher on macOS and then add this simple script in your ~/.zshrc file:

autoload -U add-zsh-hook
load-valetphprc() {
  [[ -a .valetphprc ]] || return
  local php_version=$(php -r "echo PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;")
  local valetphprc_path=".valetphprc"

  if [ -f "$valetphprc_path" ]; then
    local valetphprc_version="$(cat "${valetphprc_path}")"

    if [ "php@$php_version" != "$valetphprc_version" ]; then
      valet use
    fi
  fi
}
add-zsh-hook chpwd load-valetphprc

Now when you cd into your project directory, if a .valetphprc file with a valid version of PHP is found (e.g. php@7.4) the valet use command will be run automatically giving you one less thing to think about when working across multiple projects.

The City of Los Angeles

It’s me! Matt Stone. It was our last full day in Los Angeles and we decided to see some local sights. We travelled to Griffith Park to hike up the hill to the world famous Griffith Observatory made famous by Hollywood movies and containing an amazing science museum and of course the observatory. We then went and met our friend James for lunch and ended up at Santa Monica beach and the Pier where my brother Morgan finally got to have a go on his skateboard.

On our trip to Los Angeles where we spent most of our time at Disneyland, Anaheim (video here: https://www.youtube.com/watch?v=jY1DTQZ25vA), we also did a day trip into the California desert along Route 66 as far as we could drive in half a day (video here: https://www.youtube.com/watch?v=girtVmd_dow).

Don’t forget to subscribe to my channel and also follow me on social media for more interesting content:
https://www.twitter.com/MeMattStone
https://www.instagram.com/MeMattStone

The locations were:

Griffith Park, Los Angeles, CA USA – https://www.laparks.org/griffithpark
Griffith Observatory, Los Angeles, CA, USA – http://griffithobservatory.org
Santa Monica Pier, Santa Monica, CA, USA – https://santamonicapier.org

The first track is Oh, My Life by Dyalla.

Download his music and follow him here:
http://dyalla.com/home/
https://soundcloud.com/dyallas
https://dyalla.bandcamp.com
http://youtube.com/dyalla
https://www.patreon.com/dyalla
https://www.facebook.com/dyallas
https://www.instagram.com/dyallas/

Filmed with a Canon G1x Mk II/Gorillapod Hybrid.