15
OctRay is a wonderful, lightweight desktop app that assists you to debug your application. There’s a free demo available that can be unlocked with a license. Ray supports PHP, Ruby, JavaScript, TypeScript, NodeJS, Go and Bash applications. After installing one of the libraries to send information to Ray, you can utilize the ray function to quickly dump stuff. Any variable(s)
that you pass to ray will be displayed.
You can download the Ray desktop application in these flavors:
When using macOS, you can also install Ray with Homebrew:
brew install --cask ray
Without a license, Ray allows you to send 10 items per session.
Third-party package requirements:
To send information to the Ray desktop app, you’ll need to install a package or library in your project. If you use Laravel, you can install this package via composer
:
composer require spatie/laravel-ray
By installing Ray this way it will also be installed in your production environment. This way your application will not break if you forget to remove a ray call. The package will not attempt to transmit information to Ray when the app environment is set to production.
Optionally, you can run an artisan command to publish the config file into the project root.
php artisan ray:publish-config
You can also append an option for ‘docker’
or ‘homestead’
to give a base configuration for those dev environments.
php artisan ray:publish-config --docker
//or
php artisan ray:publish-config --homestead
In order to use a Laravel specific functionality, you must call Ray’s service provider
in your base test case.
// add this to your base test case
protected function getPackageProviders($app)
{
return [
\Spatie\LaravelRay\RayServiceProvider::class,
];
}
Inside a Laravel application, you can utilize all methods from the framework-agnostic version.
Additionally, you can use these Laravel specific methods.
You can represent all queries that are executed by calling showQueries
(or queries).
ray()->showQueries();
User::firstWhere('email', 'john@example.com'); // this query will be displayed in Ray.
If you’re interested in how many queries a given piece of code executes, and what the runtime of those queries is, you can use countQueries
. It expects you to pass a closure in which all the executed queries will be counted.
ray()->countQueries(function() {
User::all();
User::all();
User::all();
});
You can manually send a query to Ray by calling ray()
on a query.
User::query()
->where('email', 'john@example.com')
->ray()
->first();
You can call ray()
multiple times to see how a query is being built up.
User::query()
->where('first_name', 'John')
->ray()
->where('last_name', 'Doe')
->ray()
->first();
To stop showing events, call stopShowingEvents
.
You can display all events that are executed by calling showEvents
(or events).
ray()->showEvents();
event(new TestEvent());
event(new TestEventWithParameter('my argument'));
To stop showing events, call stopShowingEvents
.
You can display all jobs that are executed by calling showJobs
(or jobs).
ray()->showJobs();
dispatch(new TestJob('my-test-job'));
To stop showing jobs, call stopShowingJobs
.
You can display all cache events using showCache
ray()->showCache()
Cache::put('my-key', ['a' => 1]);
Cache::get('my-key');
Cache::get('another-key');
To stop showing cache events, call stopShowingCache
.
You can display all HTTP client requests and responses using showHttpClientRequests
ray()->showHttpClientRequests();
Http::get('https://example.com/api/users');
To stop showing http client events, call stopShowingHttpClientRequests
.
Using the model function, you can display the attributes and relations of a model
.
ray()->model($user);
The model function can also accept multiple models and even collections.
// all of these models will be displayed in Ray
ray()->model($user, $anotherUser, $yetAnotherUser);
// all models in the collection will be display
ray()->model(User::all());
// all models in all collections will be displayed
ray()->model(User::all(), OtherModel::all());
Alternatively, you can use models()
which is an alias for model()
.
You can see the rendered version of mailable in Ray by passing a mailable to the mailable function.
ray()->mailable(new TestMailable());
You can display all views that are rendered by calling showViews
.
ray()->showViews();
// typically you'll do this in a controller
view('welcome', ['name' => 'John Doe'])->render();
There are a lot more features and options in Spatie/Ray
package. If you want to dig more then you can visit its comprehensive documentation on its official website.
Published at : 15-10-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project