4
4
5
5
use Illuminate \Database \Eloquent \Builder ;
6
6
use Illuminate \Database \Query \Builder as QueryBuilder ;
7
+ use Symfony \Component \VarDumper \VarDumper ;
7
8
8
9
class Dumper
9
10
{
10
11
/**
11
- * Dump the passed variables and end the script .
12
+ * Throws a message with an SQL query .
12
13
*
13
14
* @see https://gist.github.com/Ellrion/561fc48894a87b853917e0a5cec83181#file-helper-php
14
15
*
15
16
* @param $query
16
17
* @param bool $is_short
17
- * @param bool $is_return
18
+ *
19
+ * @return void
20
+ */
21
+ public function sqlDd ($ query , bool $ is_short = false ): void
22
+ {
23
+ $ this ->sqlDump ($ query , $ is_short );
24
+
25
+ exit (1 );
26
+ }
27
+
28
+ /**
29
+ * Displays a message with an SQL query.
30
+ *
31
+ * @see https://gist.github.com/Ellrion/561fc48894a87b853917e0a5cec83181#file-helper-php
32
+ *
33
+ * @param $query
34
+ * @param bool $is_short
35
+ *
36
+ * @return array|string|void
37
+ */
38
+ public function sqlDump ($ query , bool $ is_short = false ): void
39
+ {
40
+ $ data = $ this ->sql ($ query , $ is_short );
41
+
42
+ VarDumper::dump ($ data );
43
+ }
44
+
45
+ /**
46
+ * Returns SQL query.
47
+ *
48
+ * @param $query
49
+ * @param bool $is_short
18
50
*
19
51
* @return array|string
20
52
*/
21
- public function ddSql ($ query , bool $ is_short = false , bool $ is_return = false )
53
+ public function sql ($ query , bool $ is_short = false )
22
54
{
23
55
$ query = $ this ->prepareQuery ($ query );
24
56
@@ -28,13 +60,7 @@ public function ddSql($query, bool $is_short = false, bool $is_return = false)
28
60
29
61
$ raw = $ this ->getRaw ($ sql , $ bindings );
30
62
31
- $ data = $ this ->getData ($ is_short , $ sql , $ query ->getRawBindings (), $ raw );
32
-
33
- if ($ is_return ) {
34
- return $ data ;
35
- }
36
-
37
- dd ($ data );
63
+ return $ this ->getData ($ is_short , $ sql , $ query ->getRawBindings (), $ raw );
38
64
}
39
65
40
66
protected function prepareQuery ($ query ): QueryBuilder
0 commit comments