Skip to content

Commit 70026ff

Browse files
author
Andrey Helldar
committed
Changed behavior of working with SQL dumping
1 parent a4cf032 commit 70026ff

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"illuminate/database": "^5.0|^6.0|^7.0|^8.0",
2121
"illuminate/http": "^5.0|^6.0|^7.0|^8.0",
2222
"illuminate/support": "^5.0|^6.0|^7.0|^8.0",
23-
"ramsey/uuid": "^3.7|^4.0"
23+
"ramsey/uuid": "^3.7|^4.0",
24+
"symfony/var-dumper": "^2.6|^3.0|^4.0|^5.0"
2425
},
2526
"autoload": {
2627
"psr-4": {

src/Facades/Dumper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use Illuminate\Support\Facades\Facade;
77

88
/**
9-
* @method static void|string|array ddSql($query, bool $is_short = false, bool $is_return = false)
9+
* @method static void sqlDd($query, bool $is_short = false)
10+
* @method static void sqlDump($query, bool $is_short = false)
11+
* @method static array|string sql($query, bool $is_short = false)
1012
*/
1113
class Dumper extends Facade
1214
{

src/Support/Dumper.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,53 @@
44

55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Query\Builder as QueryBuilder;
7+
use Symfony\Component\VarDumper\VarDumper;
78

89
class Dumper
910
{
1011
/**
11-
* Dump the passed variables and end the script.
12+
* Throws a message with an SQL query.
1213
*
1314
* @see https://gist.github.com/Ellrion/561fc48894a87b853917e0a5cec83181#file-helper-php
1415
*
1516
* @param $query
1617
* @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
1850
*
1951
* @return array|string
2052
*/
21-
public function ddSql($query, bool $is_short = false, bool $is_return = false)
53+
public function sql($query, bool $is_short = false)
2254
{
2355
$query = $this->prepareQuery($query);
2456

@@ -28,13 +60,7 @@ public function ddSql($query, bool $is_short = false, bool $is_return = false)
2860

2961
$raw = $this->getRaw($sql, $bindings);
3062

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);
3864
}
3965

4066
protected function prepareQuery($query): QueryBuilder

0 commit comments

Comments
 (0)