Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get full used query ? #1068

Closed
BogdanSchimbischi opened this issue Mar 15, 2017 · 7 comments
Closed

How to get full used query ? #1068

BogdanSchimbischi opened this issue Mar 15, 2017 · 7 comments

Comments

@BogdanSchimbischi
Copy link

It is possible to get full query of Datatables on filter ? I want to make a custom csv export. Something like $datatables->getQuery() ?

  • Operating System Mac OS
  • PHP Version 5.6
  • Laravel Version 5.4
  • Laravel-Datatables Version 7.2
@yajra
Copy link
Owner

yajra commented Mar 17, 2017

I think this not yet supported/possible. Will review the code and I guess this can be considered as enhancement. Thanks!

@DMeganoski
Copy link

Would just like to point out that you can get the most recent queries from laravel itself. And since version 5.0 (I think) this is disabled by default, so you can just do

\DB::enableQueryLog();
$table = Datatables::of($query) {
    // etc.
}
$log = \DB::getQueryLog();

yajra added a commit that referenced this issue Jun 24, 2017
@yajra
Copy link
Owner

yajra commented Jun 24, 2017

Implemented on master branch and will be available on Laravel 5.5. But we can also implement on Laravel 5.4 version if needed.

$dataTable = Datatables::of(App\User::query());
$response  = $dataTable->make(true);
$query = $dataTable->getQuery()->get();

return $response;

@BogdanSchimbischi
Copy link
Author

Thank you for this new feature. Can you please implement also on Laravel 5.4 ? I see that 5.5 is major release and my project is not tested yet for 5.5

Thank you again.

@fricred
Copy link

fricred commented Sep 19, 2021

@yajra can we have the last used query without the limit? , currently i get something like

 $query = $dataTable->getQuery()->toSql();
  Log::info($query);
  
//select distinct CONCAT(users.name,' ',IFNULL(users.surname, '')) as username,
//          `users`.`id`, `users`.`country`
//        , `users`.`email`
// from `users` 
// left join `registrants` on `users`.`id` = `registrants`.`users_id`
// limit 10 offset 10 

but i want to run without the limit 10 offset 10 is for a Select all feature

@yajra
Copy link
Owner

yajra commented Sep 20, 2021

@fricred maybe ->skipPaging()->getQuery()?

@govindtotla
Copy link

I did try the same to get queries logged but no success.
My issue: when we search something, it get filtered results based on searchable colors, but there is a parent-child relationship in the same table so I need all the parent ids from the search result and then I wanted to make a data table.

but as default behavior, after all the custom processing we just pass the query builder to the data table and Datatables::of($posts) apply filter with in the method and draw the table.

Any help will be appriciable.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants