New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a CRUD Generator to the admin options #228
Closed
Closed
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e428f96
Adding a CRUD Generator to the admin options
DeveloperOnCall de57c24
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall e67c1a6
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall e6a6a4f
Merge remote-tracking branch 'origin/master'
DeveloperOnCall fdce64f
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 0d0e3a6
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 7b4e28f
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 357a6ed
Merge remote-tracking branch 'origin/master'
DeveloperOnCall a0df875
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall d833899
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall e521f27
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 58253e1
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall cc24313
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 9b50f55
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall c81a1c2
Adding a CRUD Generator to the admin options, Fixed Code Style Issues
DeveloperOnCall 07c24cd
Add missing language entries and route
DeveloperOnCall 06ac56c
Fix Page Title
DeveloperOnCall 93877f6
Change to include summernote properly to avoid insecure file inclusio…
DeveloperOnCall 9a0089f
Adding Dynamic Menu From generated CRUD Module
DeveloperOnCall d61a1f1
Route cleanup
DeveloperOnCall fe48de3
Route cleanup
DeveloperOnCall 8fe8c55
Merge remote-tracking branch 'origin/master'
DeveloperOnCall 734b6f9
Added description of new feature and instructions for changes related…
DeveloperOnCall 59aff70
Fixed Missing artisan command - rookie mistake not synching the compo…
DeveloperOnCall e325d74
Fixed Missing files
DeveloperOnCall 10946ea
Fixing extra trailing slash in stub path
DeveloperOnCall 7dbe459
Reversing change to stub path - seems the crudgenerator package has s…
DeveloperOnCall File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Artisan; | ||
use File; | ||
use Illuminate\Http\Request; | ||
use Redirect; | ||
use Response; | ||
use View; | ||
|
||
class CrudController extends Controller | ||
{ | ||
/** | ||
* Display generator. | ||
* | ||
* @return Response | ||
*/ | ||
public function getGenerator() | ||
{ | ||
return view('crudmanagement.add-crud'); | ||
} | ||
|
||
|
||
/** | ||
* Process generator. | ||
* @param Request $request | ||
* @return mixed | ||
*/ | ||
public function postGenerator(Request $request) | ||
{ | ||
$commandArg = []; | ||
$commandArg['name'] = $request->crud_name; | ||
|
||
// Make sure we do not already have this module | ||
$directories = glob(base_path().'/resources/views/*', GLOB_ONLYDIR); | ||
foreach ($directories as $dir) { | ||
$this_name = str_replace(base_path().'/resources/views/', '', $dir); | ||
$used_names[] = $this_name; | ||
} | ||
|
||
if (in_array(strtolower($request->crud_name), $used_names)) { | ||
return Redirect::back()->withErrors(['Name Exists or Restricted']); | ||
} | ||
|
||
if ($request->has('fields')) { | ||
$fieldsArray = []; | ||
$validationsArray = []; | ||
$x = 0; | ||
foreach ($request->fields as $field) { | ||
if ($request->fields_required[$x] == 1) { | ||
$validationsArray[] = $field; | ||
} | ||
|
||
$fieldsArray[] = $field.'#'.$request->fields_type[$x]; | ||
|
||
$x++; | ||
} | ||
|
||
$commandArg['--fields'] = implode(';', $fieldsArray); | ||
} | ||
|
||
if (!empty($validationsArray)) { | ||
$commandArg['--validations'] = implode('#required;', $validationsArray).'#required'; | ||
} | ||
|
||
if ($request->has('route')) { | ||
$commandArg['--route'] = $request->route; | ||
} | ||
|
||
if ($request->has('view_path')) { | ||
$commandArg['--view-path'] = $request->view_path; | ||
} | ||
|
||
if ($request->has('controller_namespace')) { | ||
$commandArg['--controller-namespace'] = $request->controller_namespace; | ||
} | ||
|
||
if ($request->has('model_namespace')) { | ||
$commandArg['--model-namespace'] = $request->model_namespace; | ||
} | ||
|
||
if ($request->has('route_group')) { | ||
$commandArg['--route-group'] = $request->route_group; | ||
} | ||
|
||
if ($request->has('relationships')) { | ||
$commandArg['--relationships'] = $request->relationships; | ||
} | ||
|
||
if ($request->has('form_helper')) { | ||
$commandArg['--form-helper'] = $request->form_helper; | ||
} | ||
|
||
if ($request->has('soft_deletes')) { | ||
$commandArg['--soft-deletes'] = $request->soft_deletes; | ||
} | ||
|
||
try { | ||
Artisan::call('crud:generate', $commandArg); | ||
|
||
$menus = json_decode(File::get(base_path('resources/laravel-admin/menus.json'))); | ||
|
||
$name = $commandArg['name']; | ||
$routeName = ($commandArg['--route-group']) ? $commandArg['--route-group'].'/'.snake_case($name, '-') : snake_case($name, '-'); | ||
|
||
$menus->menus = array_map(function($menu) use ($name, $routeName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected 1 space after FUNCTION keyword; 0 found |
||
if ($menu->section == 'Resources') { | ||
array_push($menu->items, (object) [ | ||
'title' => $name, | ||
'url' => '/'.$routeName, | ||
]); | ||
} | ||
|
||
return $menu; | ||
}, $menus->menus); | ||
|
||
File::put(base_path('resources/laravel-admin/menus.json'), json_encode($menus)); | ||
|
||
Artisan::call('migrate'); | ||
} catch (\Exception $e) { | ||
return Response::make($e->getMessage(), 500); | ||
} | ||
|
||
return redirect('crud')->with('flash_message', 'Your CRUD has been generated. See on the menu.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'custom_template' => true, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Crud Generator Template Stubs Storage Path | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you can specify your custom template path for the generator. | ||
| | ||
*/ | ||
|
||
'path' => base_path('resources/crud-generator/'), | ||
|
||
/* | ||
* Columns number to show in view's table. | ||
*/ | ||
'view_columns_number' => 3, | ||
|
||
/* | ||
* Delimiter for template vars | ||
*/ | ||
'custom_delimiter' => ['%%', '%%'], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Dynamic templating | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you can specify your customs templates for the generator. | ||
| You can set new templates or delete some templates if you do not want them. | ||
| You can also choose which values are passed to the views and you can specify a custom delimiter for all templates | ||
| | ||
| Those values are available : | ||
| | ||
| formFields | ||
| formFieldsHtml | ||
| varName | ||
| crudName | ||
| crudNameCap | ||
| crudNameSingular | ||
| primaryKey | ||
| modelName | ||
| modelNameCap | ||
| viewName | ||
| routePrefix | ||
| routePrefixCap | ||
| routeGroup | ||
| formHeadingHtml | ||
| formBodyHtml | ||
| | ||
| | ||
*/ | ||
'dynamic_view_template' => [ | ||
'index' => ['formHeadingHtml', 'formBodyHtml', 'crudName', 'crudNameCap', 'modelName', 'viewName', 'routeGroup', 'primaryKey'], | ||
'form' => ['formFieldsHtml'], | ||
'create' => ['crudName', 'crudNameCap', 'modelName', 'modelNameCap', 'viewName', 'routeGroup', 'viewTemplateDir'], | ||
'edit' => ['crudName', 'crudNameSingular', 'crudNameCap', 'modelNameCap', 'modelName', 'viewName', 'routeGroup', 'primaryKey', 'viewTemplateDir'], | ||
'show' => ['formHeadingHtml', 'formBodyHtml', 'formBodyHtmlForShowView', 'crudName', 'crudNameSingular', 'crudNameCap', 'modelName', 'viewName', 'routeGroup', 'primaryKey'], | ||
/* | ||
* Add new stubs templates here if you need to, like action, datatable... | ||
* custom_template needs to be activated for this to work | ||
*/ | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@extends('layouts.app') | ||
|
||
@section('content') | ||
<div class="container"> | ||
<div class="row"> | ||
|
||
|
||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header">Create New %%modelName%%</div> | ||
<div class="card-body"> | ||
<a href="{{ url('/%%routeGroup%%%%viewName%%') }}" title="Back"><button class="btn btn-warning btn-sm"><i class="fa fa-arrow-left" aria-hidden="true"></i> Back</button></a> | ||
<br /> | ||
<br /> | ||
|
||
@if ($errors->any()) | ||
<ul class="alert alert-danger"> | ||
@foreach ($errors->all() as $error) | ||
<li>{{ $error }}</li> | ||
@endforeach | ||
</ul> | ||
@endif | ||
|
||
<form method="POST" action="{{ url('/%%routeGroup%%%%viewName%%') }}" accept-charset="UTF-8" class="form-horizontal" enctype="multipart/form-data"> | ||
{{ csrf_field() }} | ||
|
||
@include ('%%viewTemplateDir%%.form', ['formMode' => 'create']) | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@extends('layouts.app') | ||
|
||
@section('content') | ||
<div class="container"> | ||
<div class="row"> | ||
|
||
|
||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header">Edit %%modelName%% #{{ $%%crudNameSingular%%->%%primaryKey%% }}</div> | ||
<div class="card-body"> | ||
<a href="{{ url('/%%routeGroup%%%%viewName%%') }}" title="Back"><button class="btn btn-warning btn-sm"><i class="fa fa-arrow-left" aria-hidden="true"></i> Back</button></a> | ||
<br /> | ||
<br /> | ||
|
||
@if ($errors->any()) | ||
<ul class="alert alert-danger"> | ||
@foreach ($errors->all() as $error) | ||
<li>{{ $error }}</li> | ||
@endforeach | ||
</ul> | ||
@endif | ||
|
||
<form method="POST" action="{{ url('/%%routeGroup%%%%viewName%%/' . $%%crudNameSingular%%->%%primaryKey%%) }}" accept-charset="UTF-8" class="form-horizontal" enctype="multipart/form-data"> | ||
{{ method_field('PATCH') }} | ||
{{ csrf_field() }} | ||
|
||
@include ('%%viewTemplateDir%%.form', ['formMode' => 'edit']) | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
6 changes: 6 additions & 0 deletions
6
resources/crud-generator/views/html/form-fields/checkbox-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="checkbox"> | ||
<label><input name="{{ %1$s }}" type="checkbox" value="1" {{ (isset($%%crudNameSingular%%) && 1 == $%%crudNameSingular%%->%1$s) ? 'checked' : '' }}> Yes</label> | ||
</div> | ||
<div class="checkbox"> | ||
<label><input name="{{ %1$s }}" type="checkbox" value="0" {{ (isset($%%crudNameSingular%%) && 0 == $%%crudNameSingular%%->%1$s) ? 'checked' : '' }}> No</label> | ||
</div> |
1 change: 1 addition & 0 deletions
1
resources/crud-generator/views/html/form-fields/form-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input class="form-control" name="%%itemName%%" type="%%fieldType%%" id="%%itemName%%" value="{{ isset($%%crudNameSingular%%->%%itemName%%) ? $%%crudNameSingular%%->%%itemName%% : ''}}" %%required%%> |
1 change: 1 addition & 0 deletions
1
resources/crud-generator/views/html/form-fields/input-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input class="form-control" name="%%itemName%%" type="%%fieldType%%" id="%%itemName%%" value="{{ isset($%%crudNameSingular%%->%%itemName%%) ? $%%crudNameSingular%%->%%itemName%% : ''}}" %%required%%> |
1 change: 1 addition & 0 deletions
1
resources/crud-generator/views/html/form-fields/password-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input class="form-control" name="%%itemName%%" type="password" id="%%itemName%%" %%required%%> |
6 changes: 6 additions & 0 deletions
6
resources/crud-generator/views/html/form-fields/radio-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="radio"> | ||
<label><input name="%%itemName%%" type="radio" value="1" {{ (isset($%%crudNameSingular%%) && 1 == $%%crudNameSingular%%->%%itemName%%) ? 'checked' : '' }}> Yes</label> | ||
</div> | ||
<div class="radio"> | ||
<label><input name="%%itemName%%" type="radio" value="0" @if (isset($%%crudNameSingular%%)) {{ (0 == $%%crudNameSingular%%->%%itemName%%) ? 'checked' : '' }} @else {{ 'checked' }} @endif> No</label> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
resources/crud-generator/views/html/form-fields/select-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<select name="%%itemName%%" class="form-control" id="%%itemName%%" %%required%%> | ||
@foreach (json_decode('%%options%%', true) as $optionKey => $optionValue) | ||
<option value="{{ $optionKey }}" {{ (isset($%%crudNameSingular%%->%%itemName%%) && $%%crudNameSingular%%->%%itemName%% == $optionKey) ? 'selected' : ''}}>{{ $optionValue }}</option> | ||
@endforeach | ||
</select> |
1 change: 1 addition & 0 deletions
1
resources/crud-generator/views/html/form-fields/textarea-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<textarea class="form-control summernote" rows="5" name="%%itemName%%" type="%%fieldType%%" id="%%itemName%%" %%required%%>{{ isset($%%crudNameSingular%%->%%itemName%%) ? $%%crudNameSingular%%->%%itemName%% : ''}}</textarea> |
5 changes: 5 additions & 0 deletions
5
resources/crud-generator/views/html/form-fields/wrap-field.blade.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="form-group {{ $errors->has('%1$s') ? 'has-error' : ''}}"> | ||
<label for="%1$s" class="control-label">{{ %2$s }}</label> | ||
%3$s | ||
{!! $errors->first('%1$s', '<p class="help-block">:message</p>') !!} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%%formFieldsHtml%% | ||
|
||
<div class="form-group"> | ||
<input class="btn btn-primary" type="submit" value="{{ $formMode === 'edit' ? 'Update' : 'Create' }}"> | ||
</div> | ||
|
||
@include('scripts.summernote') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be one blank line after the last USE statement; 2 found;