Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\Feature;
  4.  
  5. use App;
  6. use App\Models\Application;
  7. use App\Models\Client;
  8. use App\Notifications\ApplicationCreatedNotification;
  9. use App\Notifications\ApplicationStatusPositiveNotification;
  10. use DB;
  11. use Illuminate\Support\Debug\Dumper;
  12. use Tests\TestCase;
  13.  
  14. class DocQueryTest extends TestCase
  15. {
  16.     /**
  17.      * A basic test example.
  18.      *
  19.      * @return void
  20.      */
  21.     public function testBasicTest()
  22.     {
  23.         DB::enableQueryLog();
  24.         $result = DB::table("applications")
  25.             ->select(
  26.                 "applications.id",
  27.                 DB::raw("DATE(applications.created_at) AS created"),
  28.                 DB::raw("count(application_docs.id) AS doc_cnt"),
  29.                 DB::raw("count(notification_messages.id) AS msg_cnt")
  30.             )
  31.             ->leftJoin(
  32.                 "application_docs",
  33.                 "application_docs.application_id",
  34.                 "=",
  35.                 "applications.id"
  36.             )
  37.             ->leftJoin("notification_messages", function ($join) {
  38.                 $join->on("notification_messages.application_id", "=", "applications.id")
  39.                     ->on("notification_messages.message_id", "=", DB::raw("'App\\Notifications\\ApplicationNeedDocumentsNotification'"));
  40.             })
  41.             ->whereIn("applications.status_id", [1, 2])
  42.             ->where("applications.created_at", ">", DB::raw("NOW() - INTERVAL 1 WEEK"))
  43.             ->groupBy("applications.id")
  44.             ->havingRaw("count(application_docs.id) = 0")
  45.             ->havingRaw("count(notification_messages.id) = 0")
  46.             ->get();
  47.  
  48.         $log = DB::getQueryLog();
  49.         $lastQuery = array_pop($log);
  50.  
  51.         $dumper = new Dumper();
  52.         $dumper->dump($lastQuery["query"]);
  53.         $dumper->dump($result);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement