Browse Source

Add edit view stub for full crud

tags/1.0.0
Nafies Luthfi 8 years ago
parent
commit
633a01bf48
  1. 1
      src/Generators/FormViewGenerator.php
  2. 23
      src/stubs/view-edit.stub
  3. 34
      tests/Generators/ViewsGeneratorTest.php

1
src/Generators/FormViewGenerator.php

@ -18,6 +18,7 @@ class FormViewGenerator extends BaseGenerator
$this->generateFile($viewPath.'/forms.blade.php', $this->getContent('view-forms'));
} else {
$this->generateFile($viewPath.'/create.blade.php', $this->getContent('view-create'));
$this->generateFile($viewPath.'/edit.blade.php', $this->getContent('view-edit'));
}
$this->command->info($this->modelNames['model_name'].' form view file generated.');

23
src/stubs/view-edit.stub

@ -0,0 +1,23 @@
@extends('layouts.app')
@section('title', trans('master.edit'))
@section('content')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('master.edit') }}</h3></div>
{!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
<div class="panel-body">
{!! FormField::text('name', ['required' => true, 'label' => trans('master.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('master.description')]) !!}
</div>
<div class="panel-footer">
{!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('masters.show', trans('app.cancel'), [$editableMaster], ['class' => 'btn btn-default']) }}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@endsection

34
tests/Generators/ViewsGeneratorTest.php

@ -111,6 +111,40 @@ class ViewsGeneratorTest extends TestCase
}
/** @test */
public function it_creates_correct_edit_view_content()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$editFormViewPath = resource_path("views/{$this->table_name}/edit.blade.php");
$this->assertFileExists($editFormViewPath);
$editFormViewContent = "@extends('layouts.app')
@section('title', trans('{$this->lang_name}.edit'))
@section('content')
<div class=\"row\">
<div class=\"col-md-6 col-md-offset-3\">
<div class=\"panel panel-default\">
<div class=\"panel-heading\"><h3 class=\"panel-title\">{{ trans('{$this->lang_name}.edit') }}</h3></div>
{!! Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}->id],'method' => 'patch']) !!}
<div class=\"panel-body\">
{!! FormField::text('name', ['required' => true, 'label' => trans('{$this->lang_name}.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('{$this->lang_name}.description')]) !!}
</div>
<div class=\"panel-footer\">
{!! Form::submit(trans('{$this->lang_name}.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('{$this->table_name}.show', trans('app.cancel'), [\$editable{$this->model_name}], ['class' => 'btn btn-default']) }}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@endsection
";
$this->assertEquals($editFormViewContent, file_get_contents($editFormViewPath));
}
/** @test */
public function it_not_gives_warning_message_if_default_layout_view_does_exists()
{
$defaultLayoutView = config('simple-crud.default_layout_view');

Loading…
Cancel
Save