This post is not sponsored and covers my experience with using Ray.
- Craft CMS
- and more
Since I started coding, Dump & Die has been the way I have debugged applications. I never enjoyed using xdebug as I found it clunky and a pain to set up - I hear this is less of a problem now.
When Spatie announced the release of Ray I wasn't completely sure what to think. Ray felt like it was just a UI that wrapped my debug statements and brought me out the browser.
Since they have a limited trial available I thought I would give it a spin anyway and see if it could help. After a few days I was happy to buy Ray and found it helped me out for a few reasons:
- A history of debug statements. No more forgetting the last thing you dumped and having to redo it again. Statements can be grouped into different pages to make finding them easier.
- When running tests you can send the output to ray. The same goes for console commands, jobs, events, and - well - any code in your application. No running through the terminal to find the output!
- When calling
ray($someData)it will work out the best way to interpret the data. Whether that is a model, image, string, or anything else. If you want the full log you can get that by using the
- Handy shortcuts to bring ray in and out of view - making debugging quick.
- A lot of services integrate with ray (and it is growing every week). This makes it useful for collating debugging statements into one interface.
- You can install ray to your production dependencies. When code is in a production environment any
ray()statements will silently fail instead of displaying to the user.
How to use Ray
To get all queries executed between lines of code you can use the
showQueries method which begins tracking them.
ray()->showQueries(); User::find(3); ray()->stopShowingQueries();
model() method prints out an array of the model's data to
ray. You can also get the full output by using the
ray()->model($user); // Shows an array of values.
ray()->raw($user); // prints out the full output of $user.
To see the rendered version of a mailable you can use
To check an image you can use the
image() method to have it displayed in ray.
There are a lot of handy methods included within ray so far and more are being added as the team release updates. If you've been hesitating giving ray a try I'd highly recommend downloading the trial and giving it a play.