-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
140 lines (123 loc) · 4.39 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="vendor/twbs/bootstrap/assets/ico/favicon.png">
<title>Laravel Seeder</title>
<!-- Bootstrap core CSS -->
<link href="vendor/twbs/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee;
}
</style>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="vendor/twbs/bootstrap/assets/js/html5shiv.js"></script>
<script src="vendor/twbs/bootstrap/assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="well">
<h2>Generate database seed file for laravel</h2>
<p>Enter the form below and click Generate</p>
</div>
<div class="well">
<form method="post" class="form-inline" title="lvgenerate" role="form">
<div class="form-group">
<label class="sr-only" for="dbusername">DB Username</label>
<input name="dbusername" type="text" class="form-control" id="dbusername" placeholder="Enter Username" value="<?php echo isset($_POST['dbusername'])?$_POST['dbusername']:'' ?>">
</div>
<div class="form-group">
<label class="sr-only" for="dbpassword">DB Password</label>
<input name="dbpassword" type="password" class="form-control" id="dbpassword" placeholder="Enter Password" value="<?php echo isset($_POST['dbpassword'])?$_POST['dbpassword']:'' ?>">
</div>
<div class="form-group">
<label class="sr-only" for="dbhost">DB Host</label>
<input name="dbhost" type="text" class="form-control" id="dbhost" placeholder="Database Host" value="<?php echo isset($_POST['dbhost'])?$_POST['dbhost']:'' ?>">
</div>
<div class="form-group">
<label class="sr-only" for="dbname">DB Name</label>
<input name="dbname" type="text" class="form-control" id="dbname" placeholder="Database Name" value="<?php echo isset($_POST['dbname'])?$_POST['dbname']:'' ?>">
</div>
<div class="form-group">
<label class="sr-only" for="dbtable">DB Table</label>
<input name="dbtable" type="text" class="form-control" id="dbtable" placeholder="Table Name" value="<?php echo isset($_POST['dbtable'])?$_POST['dbtable']:'' ?>">
</div>
<button type="submit" class="btn btn-default">Generate</button>
</form>
</div>
<?php
// Include ezSQL core
include_once "vendor/jv2222/ezsql/shared/ez_sql_core.php";
// Include ezSQL database specific component
include_once "vendor/jv2222/ezsql/mysql/ez_sql_mysql.php";
// Initialise database object and establish a connection
// at the same time - db_user / db_password / db_name / db_host
if ( isset($_POST) && !empty($_POST['dbusername']) ) {
$dbhost = $_POST['dbhost'];
$dbusername = $_POST['dbusername'];
$dbpassword = $_POST['dbpassword'];
$dbname = $_POST['dbname'];
$dbtable = $_POST['dbtable'];
$db = new ezSQL_mysql($dbusername,$dbpassword,$dbname,$dbhost);
}
$seeds = $db->get_results("SELECT * FROM $dbtable",ARRAY_A);
//$db->debug();
?>
<div class="well">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filename" class="col-lg-2 control-label">Filename</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="filename" value="<?php echo ucwords($dbtable); ?>TableSeeder.php">
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-lg-2 control-label">Data</label>
<div class="col-lg-10">
<textarea class="form-control" rows="20">
<?php
/**
* Seed <?php echo $dbtable ?> table
*/
class <?php echo ucwords($dbtable); ?>TableSeeder extends Seeder {
public function run()
{
DB::table('<?php echo $dbtable ?>')->delete();
$<?php echo $dbtable ?> = array(
<?php
if ($seeds){
foreach ($seeds as $seed) {
echo "\t\t\tarray(\n";
unset($seed['id']);
unset($seed['created_at']);
unset($seed['updated_at']);
foreach ($seed as $key => $value) {
echo "\t\t\t\t'".$key."'"."=>".'"'.$value.'"'.",\n";
}
echo "\t\t\t\t'created_at' => new DateTime,\n";
echo "\t\t\t\t'updated_at' => new DateTime,\n";
echo "\t\t\t".'),'."\n";
}
}
?>
);
DB::table('<?php echo $dbtable ?>')->insert( $<?php echo $dbtable ?> );
}
}
</textarea>
</div>
</div>
</form>
</div>
</div>
</body>
</html>