generathor-laravel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +419 -0
- package/dist/configuration.d.ts +25 -0
- package/dist/configuration.js +43 -0
- package/dist/helpers/handlebars.d.ts +3 -0
- package/dist/helpers/handlebars.js +20 -0
- package/dist/helpers/naming.d.ts +18 -0
- package/dist/helpers/naming.js +98 -0
- package/dist/helpers/string.d.ts +27 -0
- package/dist/helpers/string.js +120 -0
- package/dist/helpers/type.d.ts +4 -0
- package/dist/helpers/type.js +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/template.d.ts +20 -0
- package/dist/template.js +284 -0
- package/dist/transformers/collection/attachForm.d.ts +4 -0
- package/dist/transformers/collection/attachForm.js +55 -0
- package/dist/transformers/collection/attachRequest.d.ts +5 -0
- package/dist/transformers/collection/attachRequest.js +92 -0
- package/dist/transformers/collection/base.d.ts +20 -0
- package/dist/transformers/collection/base.js +54 -0
- package/dist/transformers/collection/baseController.d.ts +4 -0
- package/dist/transformers/collection/baseController.js +14 -0
- package/dist/transformers/collection/belongsToRelation.d.ts +5 -0
- package/dist/transformers/collection/belongsToRelation.js +86 -0
- package/dist/transformers/collection/controller.d.ts +8 -0
- package/dist/transformers/collection/controller.js +163 -0
- package/dist/transformers/collection/createRelationForm.d.ts +4 -0
- package/dist/transformers/collection/createRelationForm.js +163 -0
- package/dist/transformers/collection/filterRelationForm.d.ts +4 -0
- package/dist/transformers/collection/filterRelationForm.js +164 -0
- package/dist/transformers/collection/hasManyRelation.d.ts +5 -0
- package/dist/transformers/collection/hasManyRelation.js +91 -0
- package/dist/transformers/collection/menu.d.ts +4 -0
- package/dist/transformers/collection/menu.js +25 -0
- package/dist/transformers/collection/route.d.ts +5 -0
- package/dist/transformers/collection/route.js +123 -0
- package/dist/transformers/item/base.d.ts +19 -0
- package/dist/transformers/item/base.js +33 -0
- package/dist/transformers/item/edit.d.ts +4 -0
- package/dist/transformers/item/edit.js +21 -0
- package/dist/transformers/item/eloquent.d.ts +4 -0
- package/dist/transformers/item/eloquent.js +158 -0
- package/dist/transformers/item/filter.d.ts +5 -0
- package/dist/transformers/item/filter.js +41 -0
- package/dist/transformers/item/forms.d.ts +4 -0
- package/dist/transformers/item/forms.js +226 -0
- package/dist/transformers/item/laravel.d.ts +15 -0
- package/dist/transformers/item/laravel.js +36 -0
- package/dist/transformers/item/list.d.ts +4 -0
- package/dist/transformers/item/list.js +36 -0
- package/dist/transformers/item/requests.d.ts +4 -0
- package/dist/transformers/item/requests.js +125 -0
- package/dist/transformers/item/show.d.ts +5 -0
- package/dist/transformers/item/show.js +54 -0
- package/package.json +46 -0
- package/templates/eloquent/child.handlebars +13 -0
- package/templates/eloquent/filter.handlebars +88 -0
- package/templates/eloquent/parent.handlebars +64 -0
- package/templates/others/base-controller.handlebars +46 -0
- package/templates/others/controller.handlebars +185 -0
- package/templates/others/pk-trait.handlebars +157 -0
- package/templates/others/request.handlebars +32 -0
- package/templates/others/routes.handlebars +16 -0
- package/templates/views/breadcrumbs.handlebars +21 -0
- package/templates/views/edit.handlebars +41 -0
- package/templates/views/form.handlebars +103 -0
- package/templates/views/icons/check-circle.handlebars +3 -0
- package/templates/views/icons/chevron-down.handlebars +3 -0
- package/templates/views/icons/chevron-right.handlebars +3 -0
- package/templates/views/icons/computer.handlebars +3 -0
- package/templates/views/icons/eye.handlebars +4 -0
- package/templates/views/icons/funnel.handlebars +3 -0
- package/templates/views/icons/home.handlebars +3 -0
- package/templates/views/icons/link.handlebars +3 -0
- package/templates/views/icons/list-bullet.handlebars +3 -0
- package/templates/views/icons/pencil.handlebars +3 -0
- package/templates/views/icons/plus.handlebars +3 -0
- package/templates/views/icons/trash.handlebars +3 -0
- package/templates/views/icons/unlink.handlebars +3 -0
- package/templates/views/icons/x-circle.handlebars +3 -0
- package/templates/views/icons/x.handlebars +3 -0
- package/templates/views/index.handlebars +181 -0
- package/templates/views/loader.handlebars +6 -0
- package/templates/views/menu.handlebars +39 -0
- package/templates/views/modal.handlebars +36 -0
- package/templates/views/record-input.handlebars +90 -0
- package/templates/views/relation-item.handlebars +180 -0
- package/templates/views/relation-list.handlebars +199 -0
- package/templates/views/show.handlebars +134 -0
- package/templates/views/tabs.handlebars +16 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace {{namespace}};
|
|
4
|
+
|
|
5
|
+
use EloquentFilter\ModelFilter;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Automatically generated by Generathor
|
|
9
|
+
*
|
|
10
|
+
* Class {{class}}
|
|
11
|
+
*/
|
|
12
|
+
class {{class}} extends ModelFilter
|
|
13
|
+
{
|
|
14
|
+
protected $drop_id = false;
|
|
15
|
+
{{#each columns}}
|
|
16
|
+
{{#if (eq type "record")}}
|
|
17
|
+
|
|
18
|
+
public function {{attribute}}($value)
|
|
19
|
+
{
|
|
20
|
+
return $this->where('{{name}}', $value);
|
|
21
|
+
}
|
|
22
|
+
{{else if (eq type "pk")}}
|
|
23
|
+
|
|
24
|
+
public function {{attribute}}($value)
|
|
25
|
+
{
|
|
26
|
+
return $this->where('{{name}}', $value);
|
|
27
|
+
}
|
|
28
|
+
{{else if (eq type "int")}}
|
|
29
|
+
|
|
30
|
+
public function {{attribute}}From($value)
|
|
31
|
+
{
|
|
32
|
+
return $this->where('{{name}}', '>=', $value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public function {{attribute}}To($value)
|
|
36
|
+
{
|
|
37
|
+
return $this->where('{{name}}', '<=', $value);
|
|
38
|
+
}
|
|
39
|
+
{{else if (eq type "float")}}
|
|
40
|
+
|
|
41
|
+
public function {{attribute}}From($value)
|
|
42
|
+
{
|
|
43
|
+
return $this->where('{{name}}', '>=', $value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public function {{attribute}}To($value)
|
|
47
|
+
{
|
|
48
|
+
return $this->where('{{name}}', '<=', $value);
|
|
49
|
+
}
|
|
50
|
+
{{else if (eq type "bool")}}
|
|
51
|
+
|
|
52
|
+
public function {{attribute}}($value)
|
|
53
|
+
{
|
|
54
|
+
if ($value === '1') {
|
|
55
|
+
return $this->where('{{name}}', true);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return $this->where(function ($query) {
|
|
59
|
+
$query->whereNull('{{name}}')
|
|
60
|
+
->orWhere('{{name}}', false);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
{{else if (eq type "string")}}
|
|
64
|
+
|
|
65
|
+
public function {{attribute}}($value)
|
|
66
|
+
{
|
|
67
|
+
return $this->where('{{name}}', 'LIKE', "%$value%");
|
|
68
|
+
}
|
|
69
|
+
{{else if (eq type "date")}}
|
|
70
|
+
|
|
71
|
+
public function {{attribute}}From($value)
|
|
72
|
+
{
|
|
73
|
+
return $this->where('{{name}}', '>=', $value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public function {{attribute}}To($value)
|
|
77
|
+
{
|
|
78
|
+
return $this->where('{{name}}', '<=', $value);
|
|
79
|
+
}
|
|
80
|
+
{{else}}
|
|
81
|
+
|
|
82
|
+
public function {{attribute}}($value)
|
|
83
|
+
{
|
|
84
|
+
return $this->where('{{name}}', $value);
|
|
85
|
+
}
|
|
86
|
+
{{/if}}
|
|
87
|
+
{{/each}}
|
|
88
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace {{namespace}}\Generathor;
|
|
4
|
+
|
|
5
|
+
{{#each imports}}use {{this}};
|
|
6
|
+
{{/each}}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Automatically generated by Generathor
|
|
10
|
+
*
|
|
11
|
+
* Class {{model}}
|
|
12
|
+
* This is the model class for the table "{{table}}"
|
|
13
|
+
*
|
|
14
|
+
{{#each attributes}}
|
|
15
|
+
* @property{{#if type}} {{type}}{{/if}} ${{name}}
|
|
16
|
+
{{/each}}{{#each onlyReadAttributes}} * @property-read {{{type}}} ${{name}}
|
|
17
|
+
{{/each}}
|
|
18
|
+
*/
|
|
19
|
+
abstract class {{model}} extends Model
|
|
20
|
+
{
|
|
21
|
+
use Filterable;
|
|
22
|
+
use GenerathorKey;
|
|
23
|
+
use Sortable;
|
|
24
|
+
|
|
25
|
+
{{#each constants}}
|
|
26
|
+
const {{name}} = '{{value}}';
|
|
27
|
+
|
|
28
|
+
{{/each}}
|
|
29
|
+
protected $primaryKey = {{{primaryKey}}};
|
|
30
|
+
{{#unless autoincrement}}
|
|
31
|
+
|
|
32
|
+
public $incrementing = false;
|
|
33
|
+
{{/unless}}
|
|
34
|
+
{{#unless timestamps}}
|
|
35
|
+
|
|
36
|
+
public $timestamps = false;
|
|
37
|
+
{{/unless}}
|
|
38
|
+
|
|
39
|
+
public $sortable = [{{#each attributes}}
|
|
40
|
+
'{{name}}',{{/each}}
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The table associated with the model.
|
|
45
|
+
*
|
|
46
|
+
* @var string
|
|
47
|
+
*/
|
|
48
|
+
protected $table = '{{table}}';
|
|
49
|
+
|
|
50
|
+
public function getRecordLabel()
|
|
51
|
+
{
|
|
52
|
+
return $this->{{recordLabel}} ?? $this->getRouteKey();
|
|
53
|
+
}{{#each belongsToRelations}}
|
|
54
|
+
|
|
55
|
+
public function {{name}}()
|
|
56
|
+
{
|
|
57
|
+
return $this->belongsTo({{model}}::class{{#if reference}}, '{{reference.foreignKey}}', '{{reference.ownerKey}}'{{/if}});
|
|
58
|
+
}{{/each}}{{#each hasManyRelations}}
|
|
59
|
+
|
|
60
|
+
public function {{name}}()
|
|
61
|
+
{
|
|
62
|
+
return $this->hasMany({{model}}::class{{#if reference}}, '{{reference.foreignKey}}', '{{reference.localKey}}'{{/if}});
|
|
63
|
+
}{{/each}}
|
|
64
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Http\Controllers\Generathor;
|
|
4
|
+
|
|
5
|
+
use App\Http\Controllers\Controller as BaseController;
|
|
6
|
+
use Closure;
|
|
7
|
+
use Illuminate\Database\QueryException;
|
|
8
|
+
use Illuminate\Http\Request;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Automatically generated by Generathor
|
|
12
|
+
* Class Controller
|
|
13
|
+
*/
|
|
14
|
+
class Controller extends BaseController
|
|
15
|
+
{
|
|
16
|
+
public function __construct()
|
|
17
|
+
{
|
|
18
|
+
$this->middleware(function (Request $request, Closure $next) {
|
|
19
|
+
$response = $next($request);
|
|
20
|
+
|
|
21
|
+
if ($response->exception instanceof QueryException) {
|
|
22
|
+
$this->withDangerMessage($response->exception->getMessage());
|
|
23
|
+
|
|
24
|
+
return back();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return $response;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private function withMessage(string $message, string $type): void
|
|
32
|
+
{
|
|
33
|
+
session()->flash('flash.banner', $message);
|
|
34
|
+
session()->flash('flash.bannerStyle', $type);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected function withDangerMessage(string $message): void
|
|
38
|
+
{
|
|
39
|
+
$this->withMessage($message, 'danger');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected function withSuccessMessage(string $message): void
|
|
43
|
+
{
|
|
44
|
+
$this->withMessage($message, 'success');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace {{namespace}};
|
|
4
|
+
|
|
5
|
+
{{#each imports}}
|
|
6
|
+
use {{this}};
|
|
7
|
+
{{/each}}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Automatically generated by Generathor
|
|
11
|
+
* Class {{class}}
|
|
12
|
+
*/
|
|
13
|
+
class {{class}} extends Controller
|
|
14
|
+
{
|
|
15
|
+
/**
|
|
16
|
+
* Display a listing of the resource.
|
|
17
|
+
*/
|
|
18
|
+
public function index({{filterRequest}} $request)
|
|
19
|
+
{
|
|
20
|
+
$list = {{model}}::filter($request->all())
|
|
21
|
+
{{#if queryRelations}}->with({{{queryRelations}}})
|
|
22
|
+
{{/if}}->sortable()
|
|
23
|
+
->paginate(20);
|
|
24
|
+
|
|
25
|
+
return view('generathor.{{context}}.index', compact('list'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Store a newly created resource in storage.
|
|
30
|
+
*/
|
|
31
|
+
public function store({{createRequest}} $request)
|
|
32
|
+
{
|
|
33
|
+
$record = new {{model}};{{#each attributes}}
|
|
34
|
+
$record->{{name}} = $request->{{#if (eq type "bool")}}has('{{name}}'){{else}}{{name}}{{/if}};{{/each}}
|
|
35
|
+
$record->save();
|
|
36
|
+
$this->withSuccessMessage('{{label}} created successfully');
|
|
37
|
+
|
|
38
|
+
if ($request->_url) {
|
|
39
|
+
return redirect($request->_url);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return to_route('generathor.{{context}}.show', ['{{recordName}}' => $record->getRouteKey()]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Display the specified resource.
|
|
47
|
+
*/
|
|
48
|
+
public function show({{model}} ${{recordName}})
|
|
49
|
+
{
|
|
50
|
+
return view('generathor.{{context}}.show', compact('{{recordName}}'));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Show the form for editing the specified resource.
|
|
55
|
+
*/
|
|
56
|
+
public function edit({{model}} ${{recordName}})
|
|
57
|
+
{
|
|
58
|
+
return view('generathor.{{context}}.edit', compact('{{recordName}}'));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Update the specified resource in storage.
|
|
63
|
+
*/
|
|
64
|
+
public function update({{updateRequest}} $request, {{model}} ${{recordName}})
|
|
65
|
+
{
|
|
66
|
+
{{#each attributes}}${{../recordName}}->{{name}} = $request->{{#if (eq type "bool")}}has('{{name}}'){{else}}{{name}}{{/if}};
|
|
67
|
+
{{/each}}${{recordName}}->save();
|
|
68
|
+
$this->withSuccessMessage('{{label}} updated successfully');
|
|
69
|
+
|
|
70
|
+
if ($request->_url) {
|
|
71
|
+
return redirect($request->_url);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return to_route('generathor.{{context}}.show', ['{{recordName}}' => ${{recordName}}->getRouteKey()]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Remove the specified resource from storage.
|
|
79
|
+
*/
|
|
80
|
+
public function destroy({{model}} ${{recordName}}, Request $request)
|
|
81
|
+
{
|
|
82
|
+
${{recordName}}->delete();
|
|
83
|
+
$this->withSuccessMessage(__('{{label}} deleted successfully'));
|
|
84
|
+
|
|
85
|
+
if ($request->_url) {
|
|
86
|
+
return redirect($request->_url);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return back();
|
|
90
|
+
}
|
|
91
|
+
{{#each hasManyRelations}}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get {{label}} relation.
|
|
95
|
+
*/
|
|
96
|
+
public function show{{capitalizedRelationAttribute}}({{../model}} ${{../recordName}}, Filter{{model}}Request $request)
|
|
97
|
+
{
|
|
98
|
+
$list = ${{../recordName}}->{{attribute}}()
|
|
99
|
+
->filter($request->all())
|
|
100
|
+
{{#if queryRelations}}->with({{{queryRelations}}})
|
|
101
|
+
{{/if}}->sortable()
|
|
102
|
+
->paginate(20);
|
|
103
|
+
|
|
104
|
+
return view('generathor.{{../context}}.{{relationContext}}', compact('list', '{{../recordName}}'));
|
|
105
|
+
}
|
|
106
|
+
{{/each}}
|
|
107
|
+
{{#each belongsToRelations}}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get {{label}} relation.
|
|
111
|
+
*/
|
|
112
|
+
public function show{{capitalizedRelationAttribute}}({{../model}} ${{../recordName}})
|
|
113
|
+
{
|
|
114
|
+
return view('generathor.{{../context}}.{{relationContext}}', compact('{{../recordName}}'));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Store a newly created resource in storage.
|
|
119
|
+
*/
|
|
120
|
+
public function store{{capitalizedRelationAttribute}}({{../model}} ${{../recordName}}, {{createRelationRequest}} $request)
|
|
121
|
+
{
|
|
122
|
+
$record = new {{model}};{{#each attributes}}
|
|
123
|
+
$record->{{name}} = $request->{{#if (eq type "bool")}}has('{{name}}'){{else}}{{name}}{{/if}};{{/each}}
|
|
124
|
+
$record->save();
|
|
125
|
+
|
|
126
|
+
{{#each references}}${{../../recordName}}->{{this}} = $record->{{@key}};
|
|
127
|
+
{{/each}}
|
|
128
|
+
${{../recordName}}->save();
|
|
129
|
+
$this->withSuccessMessage(__('{{label}} created successfully'));
|
|
130
|
+
|
|
131
|
+
return back();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Detach {{model}}.
|
|
136
|
+
*/
|
|
137
|
+
public function detach{{capitalizedRelationAttribute}}({{../model}} ${{../recordName}})
|
|
138
|
+
{
|
|
139
|
+
{{#each references}}${{../../recordName}}->{{this}} = null;
|
|
140
|
+
{{/each}}
|
|
141
|
+
${{../recordName}}->save();
|
|
142
|
+
$this->withSuccessMessage(__('{{label}} detached successfully'));
|
|
143
|
+
|
|
144
|
+
return back();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Attach {{model}}.
|
|
149
|
+
*/
|
|
150
|
+
public function attach{{capitalizedRelationAttribute}}({{../model}} ${{../recordName}}, {{attachRelationRequest}} $request)
|
|
151
|
+
{
|
|
152
|
+
{{#each references}}${{../../recordName}}->{{this}} = $request->{{this}};
|
|
153
|
+
{{/each}}
|
|
154
|
+
${{../recordName}}->save();
|
|
155
|
+
$this->withSuccessMessage(__('{{label}} attached successfully'));
|
|
156
|
+
|
|
157
|
+
return back();
|
|
158
|
+
}
|
|
159
|
+
{{/each}}
|
|
160
|
+
{{#if search}}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Search {{model}}
|
|
164
|
+
*/
|
|
165
|
+
public function search()
|
|
166
|
+
{
|
|
167
|
+
$term = request()->query('term');
|
|
168
|
+
if (! is_string($term)) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {{model}}::query()
|
|
173
|
+
->where('{{search.attribute}}', 'LIKE', "%{$term}%")
|
|
174
|
+
->orWhere('{{search.key}}', $term)
|
|
175
|
+
->limit(10)
|
|
176
|
+
->get()
|
|
177
|
+
->map(function ({{model}} $item) {
|
|
178
|
+
return [
|
|
179
|
+
'id' => $item->getKey(),
|
|
180
|
+
'label' => $item->getRecordLabel(),
|
|
181
|
+
];
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
{{/if}}
|
|
185
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Models\Generathor;
|
|
4
|
+
|
|
5
|
+
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Automatically generated by Generathor
|
|
9
|
+
*
|
|
10
|
+
* This trait is based on the original 'HasCompositeKey' from the 'thiagoprz/eloquent-composite-key' package.
|
|
11
|
+
* Original trait author: Thiago Przyczynski
|
|
12
|
+
* Source: https://github.com/thiagoprz/eloquent-composite-key
|
|
13
|
+
*/
|
|
14
|
+
trait GenerathorKey
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve the model for a bound value.
|
|
18
|
+
*
|
|
19
|
+
* @param mixed $value
|
|
20
|
+
* @param string|null $field
|
|
21
|
+
* @return \Illuminate\Database\Eloquent\Model|null
|
|
22
|
+
*/
|
|
23
|
+
public function resolveRouteBinding($value, $field = null)
|
|
24
|
+
{
|
|
25
|
+
$keys = $this->getKeyName();
|
|
26
|
+
if (! is_array($keys)) {
|
|
27
|
+
return parent::resolveRouteBinding($value, $field);
|
|
28
|
+
}
|
|
29
|
+
if (! is_string($value)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
$value = json_decode(base64_decode($value), true);
|
|
34
|
+
if (! $value) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
$query = static::query();
|
|
38
|
+
foreach ($keys as $key) {
|
|
39
|
+
if (isset($value[$key])) {
|
|
40
|
+
$query->where($key, $value[$key]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return $query->firstOrFail();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the value of the model's route key.
|
|
49
|
+
*
|
|
50
|
+
* @return mixed
|
|
51
|
+
*/
|
|
52
|
+
public function getRouteKey()
|
|
53
|
+
{
|
|
54
|
+
$keys = $this->getKeyName();
|
|
55
|
+
if (! is_array($keys)) {
|
|
56
|
+
return parent::getRouteKey();
|
|
57
|
+
}
|
|
58
|
+
$info = [];
|
|
59
|
+
foreach ($keys as $key) {
|
|
60
|
+
$info[$key] = $this->getAttribute($key);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return base64_encode(json_encode($info));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set the keys for a save update query.
|
|
68
|
+
*
|
|
69
|
+
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
70
|
+
* @return \Illuminate\Database\Eloquent\Builder
|
|
71
|
+
*/
|
|
72
|
+
protected function setKeysForSaveQuery($query)
|
|
73
|
+
{
|
|
74
|
+
$keys = $this->getKeyName();
|
|
75
|
+
|
|
76
|
+
return ! is_array($keys) ? parent::setKeysForSaveQuery($query) : $query->where(function ($q) use ($keys) {
|
|
77
|
+
foreach ($keys as $key) {
|
|
78
|
+
$q->where($key, '=', $this->getOriginal($key));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @return bool
|
|
85
|
+
*/
|
|
86
|
+
public function getIncrementing()
|
|
87
|
+
{
|
|
88
|
+
return is_array($this->getKeyName()) ? false : parent::getIncrementing();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get the value of the model's primary key.
|
|
93
|
+
*
|
|
94
|
+
* @return mixed
|
|
95
|
+
*/
|
|
96
|
+
public function getKey()
|
|
97
|
+
{
|
|
98
|
+
$keys = $this->getKeyName();
|
|
99
|
+
|
|
100
|
+
return ! is_array($keys) ? parent::getKey() : array_map(function ($key) {
|
|
101
|
+
return $this->getAttribute($key);
|
|
102
|
+
}, $keys);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Find a model by its primary key.
|
|
107
|
+
*
|
|
108
|
+
* @param mixed $id
|
|
109
|
+
* @param array|string $columns
|
|
110
|
+
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null
|
|
111
|
+
*/
|
|
112
|
+
public static function find($id, $columns = ['*'])
|
|
113
|
+
{
|
|
114
|
+
$model = new static;
|
|
115
|
+
$keys = $model->getKeyName();
|
|
116
|
+
|
|
117
|
+
if (! is_array($keys)) {
|
|
118
|
+
return $model->parentFind($id, $columns);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return $model->where(function ($query) use ($id, $keys) {
|
|
122
|
+
foreach ($keys as $idx => $key) {
|
|
123
|
+
if (isset($id[$idx])) {
|
|
124
|
+
$query->where($key, $id[$idx]);
|
|
125
|
+
} elseif (isset($id[$key])) {
|
|
126
|
+
$query->where($key, $id[$key]);
|
|
127
|
+
} else {
|
|
128
|
+
$query->whereNull($key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})->first($columns);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private function parentFind($id, $columns = ['*'])
|
|
135
|
+
{
|
|
136
|
+
return parent::find($id, $columns);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Find a model by its primary key or throw an exception.
|
|
141
|
+
*
|
|
142
|
+
* @param mixed $id
|
|
143
|
+
* @param array|string $columns
|
|
144
|
+
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static|static[]
|
|
145
|
+
*
|
|
146
|
+
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException<\Illuminate\Database\Eloquent\Model>
|
|
147
|
+
*/
|
|
148
|
+
public static function findOrFail($id, $columns = ['*'])
|
|
149
|
+
{
|
|
150
|
+
$record = static::find($id, $columns);
|
|
151
|
+
if (! $record) {
|
|
152
|
+
throw new ModelNotFoundException;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return $record;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace {{namespace}};
|
|
4
|
+
|
|
5
|
+
use Illuminate\Foundation\Http\FormRequest;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Automatically generated by Generathor
|
|
9
|
+
* Class {{class}}
|
|
10
|
+
*/
|
|
11
|
+
class {{class}} extends FormRequest
|
|
12
|
+
{
|
|
13
|
+
{{#if (not (eq errorBag 'default'))}} /**
|
|
14
|
+
* The key to be used for the view error bag.
|
|
15
|
+
*
|
|
16
|
+
* @var string
|
|
17
|
+
*/
|
|
18
|
+
protected $errorBag = '{{errorBag}}';
|
|
19
|
+
{{/if}}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the validation rules that apply to the request.
|
|
23
|
+
*
|
|
24
|
+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
|
25
|
+
*/
|
|
26
|
+
public function rules(): array
|
|
27
|
+
{
|
|
28
|
+
return [{{#each rules}}
|
|
29
|
+
'{{attribute}}' => '{{rules}}',{{/each}}
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests;
|
|
4
|
+
use Illuminate\Support\Facades\Route;
|
|
5
|
+
|
|
6
|
+
Route::view('/', 'generathor.menu')->name('generathor.menu');
|
|
7
|
+
{{#each this}}
|
|
8
|
+
/**
|
|
9
|
+
* {{label}} routes.
|
|
10
|
+
*/
|
|
11
|
+
Route::controller({{controller}}::class)->group(function () {
|
|
12
|
+
{{#each routes}}
|
|
13
|
+
Route::{{method}}('{{path}}', '{{action}}')->name('generathor.{{context}}.{{action}}'){{#if precognition}}->middleware([HandlePrecognitiveRequests::class]){{/if}};
|
|
14
|
+
{{/each}}
|
|
15
|
+
});
|
|
16
|
+
{{/each}}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<nav class="flex px-4 sm:px-6 lg:px-8" aria-label="Breadcrumb">
|
|
2
|
+
<ol class="inline-flex items-center space-x-1">
|
|
3
|
+
@foreach($breadcrumbs as $breadcrumb)
|
|
4
|
+
<li class="inline-flex items-center">
|
|
5
|
+
@if (!$loop->first)
|
|
6
|
+
<x-generathor.icon-chevron-right />
|
|
7
|
+
@endif
|
|
8
|
+
@if (@$loop->last)
|
|
9
|
+
<span class="text-sm font-medium text-gray-700 dark:text-gray-400">\{{$breadcrumb['label']}}</span>
|
|
10
|
+
@else
|
|
11
|
+
<a href="\{{$breadcrumb['url']}}" class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white space-x-2">
|
|
12
|
+
@if (!empty($breadcrumb['icon']))
|
|
13
|
+
<x-dynamic-component :component="$breadcrumb['icon']" />
|
|
14
|
+
@endif
|
|
15
|
+
<span>\{{$breadcrumb['label']}}</span>
|
|
16
|
+
</a>
|
|
17
|
+
@endif
|
|
18
|
+
</li>
|
|
19
|
+
@endforeach
|
|
20
|
+
</ol>
|
|
21
|
+
</nav>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<x-{{layout}}>
|
|
2
|
+
<x-slot name="header">
|
|
3
|
+
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
|
|
4
|
+
\{{__('{{header}}')}}
|
|
5
|
+
</h2>
|
|
6
|
+
</x-slot>
|
|
7
|
+
<div class="w-full bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700">
|
|
8
|
+
<div class="max-w-7xl mx-auto overflow-hidden py-2">
|
|
9
|
+
<x-generathor.breadcrumbs :breadcrumbs="[
|
|
10
|
+
[
|
|
11
|
+
'label' => __('Home'),
|
|
12
|
+
'icon' => 'generathor.icon-home',
|
|
13
|
+
'url' => route('{{homeRoute}}')
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
'label' => __('Manage'),
|
|
17
|
+
'icon' => 'generathor.icon-computer',
|
|
18
|
+
'url' => route('generathor.menu')
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
'label' => __('{{listLabel}}'),
|
|
22
|
+
'url' => route('generathor.{{context}}.index')
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
'label' => ${{recordName}}->getRecordLabel(),
|
|
26
|
+
'url' => route('generathor.{{context}}.show', ['{{recordName}}' => ${{recordName}}->getRouteKey()])
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'label' => __('Update')
|
|
30
|
+
]
|
|
31
|
+
]" />
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="max-w-7xl py-12 mx-auto sm:px-6 lg:px-8">
|
|
35
|
+
<div class="bg-white dark:bg-gray-800 shadow-xl sm:rounded-lg">
|
|
36
|
+
<div class="p-6 lg:p-8 bg-white dark:bg-gray-800 dark:bg-gradient-to-bl dark:from-gray-700/50 dark:via-transparent border-b border-gray-200 dark:border-gray-700">
|
|
37
|
+
<x-generathor.{{context}}.update-form :{{recordName}}="${{recordName}}" />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</x-{{layout}}>
|