Skip to content

Commit 59c8f6e

Browse files
author
PovilasKorop
committed
Initial first version
0 parents  commit 59c8f6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+20071
-0
lines changed

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "laraveldaily/quickadmin",
3+
"description": "Package for creating adminpanel in Laravel 5",
4+
"authors": [
5+
{
6+
"name": "ModestasV",
7+
"email": "[email protected]"
8+
},
9+
{
10+
"name": "PovilasKorop",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"version": "0.1.0",
15+
"require": {
16+
"illuminate/html": "5.0.*@dev"
17+
},
18+
"classmap": [
19+
"src/Controllers",
20+
"src/Cache",
21+
"src/Models"
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"Laraveldaily\\Quickadmin\\": "src/"
26+
}
27+
}
28+
}

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Quick Admin installation
2+
1. Install the package via `composer require quickadmin/quickadmin`.
3+
2. Add `Quickadmin\Quickadmin\QuickadminServiceProvider::class,` to your `\config\app.php` providers.
4+
3. Run `php artisan quickadmin:install` and fill the required information.
5+
4. Access QuickAdmin panel by visiting `http://yourdomain/qa`.

src/Builders/ControllerBuilder.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
namespace Laraveldaily\Quickadmin\Builders;
3+
4+
use Illuminate\Support\Str;
5+
use Laraveldaily\Quickadmin\Cache\QuickCache;
6+
7+
class ControllerBuilder
8+
{
9+
// Controller namespace
10+
private $namespace = 'App\Http\Controllers';
11+
// Template
12+
private $template;
13+
// Global names
14+
private $name;
15+
private $className;
16+
private $modelName;
17+
private $requestName;
18+
private $fileName;
19+
20+
/**
21+
* Build our controller file
22+
*/
23+
public function build()
24+
{
25+
$cache = new QuickCache();
26+
$cached = $cache->get('fieldsinfo');
27+
$this->template = __DIR__ . '/../Templates/controller';
28+
$this->name = $cached['name'];
29+
$this->fields = $cached['fields'];
30+
$this->soft = $cached['soft_delete'];
31+
$this->names();
32+
$template = (string) $this->loadTemplate();
33+
$template = $this->buildParts($template);
34+
$this->publish($template);
35+
}
36+
37+
/**
38+
* Load controller template
39+
*/
40+
private function loadTemplate()
41+
{
42+
return file_get_contents($this->template);
43+
}
44+
45+
/**
46+
* Build controller template parts
47+
*
48+
* @param $template
49+
*
50+
* @return mixed
51+
*/
52+
private function buildParts($template)
53+
{
54+
$template = str_replace([
55+
'$NAMESPACE$',
56+
'$MODEL$',
57+
'$REQUESTNAME$',
58+
'$CLASS$',
59+
'$COLLECTION$',
60+
'$RESOURCE$',
61+
], [
62+
$this->namespace,
63+
$this->modelName,
64+
$this->requestName,
65+
$this->className,
66+
strtolower($this->modelName),
67+
strtolower($this->modelName),
68+
], $template);
69+
70+
return $template;
71+
}
72+
73+
/**
74+
* Generate names
75+
*/
76+
private function names()
77+
{
78+
$camelName = ucfirst(Str::camel($this->name));
79+
$this->className = $camelName . 'Controller';
80+
$this->modelName = $camelName;
81+
$this->requestName = $camelName . 'Request';
82+
83+
$fileName = $this->className . '.php';
84+
$this->fileName = $fileName;
85+
}
86+
87+
/**
88+
* Publish file into it's place
89+
*/
90+
private function publish($template)
91+
{
92+
file_put_contents(app_path('Http/Controllers/' . $this->fileName), $template);
93+
}
94+
95+
}

src/Builders/MigrationBuilder.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
namespace Laraveldaily\Quickadmin\Builders;
3+
4+
use Illuminate\Support\Str;
5+
use Laraveldaily\Quickadmin\Cache\QuickCache;
6+
7+
class MigrationBuilder
8+
{
9+
// Template
10+
private $template;
11+
// Names
12+
private $name;
13+
private $className;
14+
private $fileName;
15+
// Fields
16+
private $fields;
17+
// Soft delete?
18+
private $soft;
19+
20+
/**
21+
* Build our migration file
22+
*/
23+
public function build()
24+
{
25+
$cache = new QuickCache();
26+
$cached = $cache->get('fieldsinfo');
27+
$this->template = __DIR__ . '/../Templates/migration';
28+
$this->name = $cached['name'];
29+
$this->fields = $cached['fields'];
30+
$this->soft = $cached['soft_delete'];
31+
$this->names();
32+
$template = (string) $this->loadTemplate();
33+
$template = $this->buildParts($template);
34+
$this->publish($template);
35+
}
36+
37+
/**
38+
* Load migration template
39+
*/
40+
private function loadTemplate()
41+
{
42+
return file_get_contents($this->template);
43+
}
44+
45+
/**
46+
* Build migration template parts
47+
*
48+
* @param $template
49+
*
50+
* @return mixed
51+
*/
52+
private function buildParts($template)
53+
{
54+
$camelName = Str::camel($this->name);
55+
$tableName = strtolower($camelName);
56+
$fields = $this->buildFields();
57+
$template = str_replace([
58+
'$TABLENAME$',
59+
'$CLASS$',
60+
'$FIELDS$'
61+
], [
62+
$tableName,
63+
$this->className,
64+
$fields
65+
], $template);
66+
67+
return $template;
68+
}
69+
70+
/**
71+
* Build migration fields
72+
* @return string
73+
*/
74+
private function buildFields()
75+
{
76+
$used = [];
77+
$fields = '$table->increments("id");' . "\r\n";
78+
foreach ($this->fields as $field) {
79+
// Check if there is no duplication for radio and checkbox
80+
if (!in_array($field->title, $used)) {
81+
$fields .= '$table->string("' . $field->title . '");' . "\r\n";
82+
$used[$field->title] = $field->title;
83+
}
84+
}
85+
if ($this->soft == 1) {
86+
$fields .= '$table->softDeletes();';
87+
}
88+
$fields .= '$table->timestamps();';
89+
90+
return $fields;
91+
}
92+
93+
/**
94+
* Generate file and class names for the migration
95+
*/
96+
private function names()
97+
{
98+
$fileName = date("Y_m_d_His") . '_create_';
99+
$fileName .= str_replace(' ', '_', $this->name);
100+
$fileName = strtolower($fileName) . '_table.php';
101+
$this->fileName = $fileName;
102+
103+
$className = 'Create' . ' ' . $this->name . ' Table';
104+
$className = Str::camel($className);
105+
$this->className = ucfirst($className);
106+
}
107+
108+
/**
109+
* Publish file into it's place
110+
*/
111+
private function publish($template)
112+
{
113+
file_put_contents(database_path('migrations/' . $this->fileName), $template);
114+
}
115+
116+
}

src/Builders/ModelBuilder.php

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
namespace Laraveldaily\Quickadmin\Builders;
3+
4+
use Illuminate\Support\Str;
5+
use Laraveldaily\Quickadmin\Cache\QuickCache;
6+
7+
class ModelBuilder
8+
{
9+
// Model namespace
10+
private $namespace = 'App';
11+
// Template
12+
private $template;
13+
// Names
14+
private $name;
15+
private $className;
16+
private $fileName;
17+
// Fields
18+
private $fields;
19+
// Soft delete?
20+
private $soft;
21+
22+
/**
23+
* Build our model file
24+
*/
25+
public function build()
26+
{
27+
$cache = new QuickCache();
28+
$cached = $cache->get('fieldsinfo');
29+
$this->template = __DIR__ . '/../Templates/model';
30+
$this->name = $cached['name'];
31+
$this->fields = $cached['fields'];
32+
$this->soft = $cached['soft_delete'];
33+
$this->names();
34+
$template = (string) $this->loadTemplate();
35+
$template = $this->buildParts($template);
36+
$this->publish($template);
37+
}
38+
39+
/**
40+
* Load model template
41+
*/
42+
private function loadTemplate()
43+
{
44+
return file_get_contents($this->template);
45+
}
46+
47+
/**
48+
* Build model template parts
49+
*
50+
* @param $template
51+
*
52+
* @return mixed
53+
*/
54+
private function buildParts($template)
55+
{
56+
$camelName = Str::camel($this->name);
57+
// Insert table names
58+
$tableName = strtolower($camelName);
59+
$fillables = $this->buildFillables();
60+
if ($this->soft == 1) {
61+
$soft_call = 'use Illuminate\Database\Eloquent\SoftDeletes;';
62+
$soft_use = 'use SoftDeletes;';
63+
$soft_date = '/**
64+
* The attributes that should be mutated to dates.
65+
*
66+
* @var array
67+
*/
68+
protected $dates = [\'deleted_at\'];';
69+
} else {
70+
$soft_call = '';
71+
$soft_use = '';
72+
$soft_date = '';
73+
}
74+
$template = str_replace([
75+
'$NAMESPACE$',
76+
'$SOFT_DELETE_CALL$',
77+
'$SOFT_DELETE_USE$',
78+
'$SOFT_DELETE_DATES$',
79+
'$TABLENAME$',
80+
'$CLASS$',
81+
'$FILLABLE$'
82+
], [
83+
$this->namespace,
84+
$soft_call,
85+
$soft_use,
86+
$soft_date,
87+
$tableName,
88+
$this->className,
89+
$fillables
90+
], $template);
91+
92+
return $template;
93+
}
94+
95+
/**
96+
* Build model fillables
97+
* @return string
98+
*/
99+
private function buildFillables()
100+
{
101+
$used = [];
102+
$fillables = '';
103+
foreach ($this->fields as $field) {
104+
// Check if there is no duplication for radio and checkbox
105+
if (!in_array($field->title, $used)) {
106+
$fillables .= "'" . $field->title . "',\r\n";
107+
$used[$field->title] = $field->title;
108+
}
109+
}
110+
111+
return $fillables;
112+
}
113+
114+
/**
115+
* Generate file and class names for the model
116+
*/
117+
private function names()
118+
{
119+
$this->className = ucfirst(Str::camel($this->name));
120+
121+
$fileName = $this->className . '.php';
122+
$this->fileName = $fileName;
123+
}
124+
125+
/**
126+
* Publish file into it's place
127+
*/
128+
private function publish($template)
129+
{
130+
file_put_contents(app_path($this->fileName), $template);
131+
}
132+
133+
}

0 commit comments

Comments
 (0)