Skip to content

Commit

Permalink
Merge pull request #46 from raphaelheitor/master
Browse files Browse the repository at this point in the history
New feature: option --prefix
  • Loading branch information
raphaelheitor authored Jun 25, 2016
2 parents 34b4178 + 8dc73e1 commit 015236a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ And don't forget to run:
php artisan migrate
```

### Other Examples (new)

Same as above with use of the prefix. It will create the prefix in redirects of controller and the links of views:
```
php artisan make:scaffold Tweet --schema="title:string:default('Tweet #1'), body:text" --prefix="admin"
```
Create the empty scaffold views, controller, seed, migration and model:
```
php artisan make:scaffold Tweet
```
Create the empty scaffold (with prefix) views, controller, seed, migration and model:
```
php artisan make:scaffold Tweet --prefix="admin"
```

## Scaffold
![image](http://i62.tinypic.com/11maveb.png)
Expand Down
11 changes: 9 additions & 2 deletions src/Makes/MakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@ private function replaceModelName(&$stub)
$model_name_uc = $this->scaffoldCommandObj->getObjName('Name');
$model_name = $this->scaffoldCommandObj->getObjName('name');
$model_names = $this->scaffoldCommandObj->getObjName('names');

$prefix = $this->scaffoldCommandObj->option('prefix');

$stub = str_replace('{{model_name_class}}', $model_name_uc, $stub);
$stub = str_replace('{{model_name_var_sgl}}', $model_name, $stub);
$stub = str_replace('{{model_name_var}}', $model_names, $stub);


if ($prefix != null)
$stub = str_replace('{{prefix}}', $prefix.'.', $stub);
else
$stub = str_replace('{{prefix}}', '', $stub);

return $this;
}

Expand All @@ -133,6 +139,7 @@ protected function replaceSchema(&$stub, $type = 'migration')
}



// Create controllers fields
$schema = (new SyntaxBuilder)->create($schema, $this->scaffoldCommandObj->getMeta(), 'controller');
$stub = str_replace('{{model_fields}}', $schema, $stub);
Expand Down
7 changes: 7 additions & 0 deletions src/Makes/MakeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ protected function replaceName(&$stub)
$stub = str_replace('{{class}}', $this->scaffoldCommandObj->getObjName('names'), $stub);
$stub = str_replace('{{classSingle}}', $this->scaffoldCommandObj->getObjName('name'), $stub);

$prefix = $this->scaffoldCommandObj->option('prefix');

if ($prefix != null)
$stub = str_replace('{{prefix}}',$prefix.'.', $stub);
else
$stub = str_replace('{{prefix}}', '', $stub);

return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class {{class}} extends Controller {

${{model_name_var_sgl}}->save();

return redirect()->route('{{model_name_var}}.index')->with('message', 'Item created successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item created successfully.');
}

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ class {{class}} extends Controller {

${{model_name_var_sgl}}->save();

return redirect()->route('{{model_name_var}}.index')->with('message', 'Item updated successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item updated successfully.');
}

/**
Expand All @@ -102,7 +102,7 @@ class {{class}} extends Controller {
${{model_name_var_sgl}} = {{model_name_class}}::findOrFail($id);
${{model_name_var_sgl}}->delete();

return redirect()->route('{{model_name_var}}.index')->with('message', 'Item deleted successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item deleted successfully.');
}

}
4 changes: 2 additions & 2 deletions src/stubs/html_assets/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<div class="row">
<div class="col-md-12">

<form action="{{ route('{{class}}.store') }}" method="POST">
<form action="{{ route('{{prefix}}{{class}}.store') }}" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">

{{content_fields}}
<div class="well well-sm">
<button type="submit" class="btn btn-primary">Create</button>
<a class="btn btn-link pull-right" href="{{ route('{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
</div>
</form>

Expand Down
4 changes: 2 additions & 2 deletions src/stubs/html_assets/edit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<div class="row">
<div class="col-md-12">

<form action="{{ route('{{class}}.update', ${{classSingle}}->id) }}" method="POST">
<form action="{{ route('{{prefix}}{{class}}.update', ${{classSingle}}->id) }}" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">

{{content_fields}}
<div class="well well-sm">
<button type="submit" class="btn btn-primary">Save</button>
<a class="btn btn-link pull-right" href="{{ route('{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
</div>
</form>

Expand Down
8 changes: 4 additions & 4 deletions src/stubs/html_assets/index.stub
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="page-header clearfix">
<h1>
<i class="glyphicon glyphicon-align-justify"></i> {{Class}}
<a class="btn btn-success pull-right" href="{{ route('{{class}}.create') }}"><i class="glyphicon glyphicon-plus"></i> Create</a>
<a class="btn btn-success pull-right" href="{{ route('{{prefix}}{{class}}.create') }}"><i class="glyphicon glyphicon-plus"></i> Create</a>
</h1>

</div>
Expand All @@ -29,9 +29,9 @@
<td>{{${{classSingle}}->id}}</td>
{{content_fields}}
<td class="text-right">
<a class="btn btn-xs btn-primary" href="{{ route('{{class}}.show', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-eye-open"></i> View</a>
<a class="btn btn-xs btn-warning" href="{{ route('{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<form action="{{ route('{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<a class="btn btn-xs btn-primary" href="{{ route('{{prefix}}{{class}}.show', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-eye-open"></i> View</a>
<a class="btn btn-xs btn-warning" href="{{ route('{{prefix}}{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<form action="{{ route('{{prefix}}{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-trash"></i> Delete</button>
Expand Down
4 changes: 2 additions & 2 deletions src/stubs/html_assets/show.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@section('header')
<div class="page-header">
<h1>{{Class}} / Show #{{${{classSingle}}->id}}</h1>
<form action="{{ route('{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<form action="{{ route('{{prefix}}{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="btn-group pull-right" role="group" aria-label="...">
Expand All @@ -25,7 +25,7 @@
{{content_fields}}
</form>

<a class="btn btn-link" href="{{ route('{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<a class="btn btn-link" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>

</div>
</div>
Expand Down

0 comments on commit 015236a

Please sign in to comment.