spatie / laravel-ray

Debug with Ray to fix problems faster in Laravel apps
https://myray.app
MIT License
291 stars 64 forks source link

Queries are displaying only when retrieving data. #205

Closed mertasan closed 3 years ago

mertasan commented 3 years ago

Describe the bug

While developing a project, I need to constantly check the db queries with ray.

But Ray expects me to get the data to print the SQL queries.

In other words, I can't see the generated queries without completing most of the project.

Versions

PHP version: 8.0.7 Laravel version: 8.5.20

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/mertasan/ray-demo
  2. Install
  3. See https://[domain].test/make-query (no results) - Source code
  4. See https://[domain].test/get-first (its working) - Source code
  5. See https://[domain].test/where (no results) - Source code

Expected behavior

All SQL queries added after the ray()->showQueries() function should be displayed in the Ray application.

Desktop (please complete the following information):

Nielsvanpach commented 3 years ago

If you don't want to execute your queries, I suggest using ->dump() and pass that to ray()

ray(DB::table('users')->where('id', 1)->dump());
mertasan commented 3 years ago

Thanks @Nielsvanpach

public function build()
{
    $this->joins();
    if($this->search){
        $this->searchQueries();
    }
    if($this->filter){
        $this->filterQueries();
    }
    $this->selectFields();
}

In a project that starts as above and consists of dozens of queries, should I do all the queries this way?

How will the proceedings proceed?

If what I want isn't possible, it's ok. But that should not be the path I should follow.

public function getRowsProperty()
{
    return $this->query->paginate($this->getTablePerPage());
}

Edit:

Note: I created random code samples. It's not a real build.

Nielsvanpach commented 3 years ago

I'm not sure what your question is.

All SQL queries added after the ray()->showQueries() function should be displayed in the Ray application.

This only happens if an actual query is executed. If you only want to build queries without executing them, I suggest to dump your query and pass them to Ray manually.