diff --git a/src/stubs/controller.model.stub b/src/stubs/controller.model.stub
index aa55307..f0e2d22 100644
--- a/src/stubs/controller.model.stub
+++ b/src/stubs/controller.model.stub
@@ -15,7 +15,9 @@ class MastersController extends Controller
public function index()
{
$editableMaster = null;
- $masters = Master::paginate(25);
+ $masters = Master::where(function ($query) {
+ $query->where('name', 'like', '%'.request('q').'%');
+ })->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
$editableMaster = Master::find(request('id'));
@@ -34,7 +36,7 @@ class MastersController extends Controller
{
$this->validate($request, [
'name' => 'required|max:60',
- 'description' => 'required|max:255',
+ 'description' => 'nullable|max:255',
]);
Master::create($request->only('name', 'description'));
@@ -53,7 +55,7 @@ class MastersController extends Controller
{
$this->validate($request, [
'name' => 'required|max:60',
- 'description' => 'required|max:255',
+ 'description' => 'nullable|max:255',
]);
$routeParam = request()->only('page', 'q');
diff --git a/src/stubs/migration-create.stub b/src/stubs/migration-create.stub
index 47aa405..591eae3 100755
--- a/src/stubs/migration-create.stub
+++ b/src/stubs/migration-create.stub
@@ -16,7 +16,7 @@ class CreateMastersTable extends Migration
Schema::create('masters', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 60);
- $table->string('description');
+ $table->string('description')->nullable();
$table->timestamps();
});
}
diff --git a/src/stubs/test-feature.stub b/src/stubs/test-feature.stub
index c81f416..fbe1eaf 100644
--- a/src/stubs/test-feature.stub
+++ b/src/stubs/test-feature.stub
@@ -49,7 +49,7 @@ class ManageMastersTest extends TestCase
public function user_can_edit_a_master_within_search_query()
{
$this->loginAsUser();
- $master = factory(Master::class)->create(['description' => 'Testing 123']);
+ $master = factory(Master::class)->create(['name' => 'Testing 123']);
$this->visit(route('masters.index', ['q' => '123']));
$this->click('edit-master-'.$master->id);
diff --git a/src/stubs/view-forms.stub b/src/stubs/view-forms.stub
index 60566af..cd06c5b 100644
--- a/src/stubs/view-forms.stub
+++ b/src/stubs/view-forms.stub
@@ -1,15 +1,14 @@
@if (Request::get('action') == 'create')
{!! Form::open(['route' => 'masters.store']) !!}
- {!! FormField::text('name') !!}
+ {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('master.create'), ['class' => 'btn btn-success']) !!}
- {!! Form::hidden('cat', 'master') !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'edit' && $editableMaster)
{!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
- {!! FormField::text('name') !!}
+ {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!}
@if (request('q'))
{{ Form::hidden('q', request('q')) }}
diff --git a/src/stubs/view-index.stub b/src/stubs/view-index.stub
index 517450f..e82b095 100644
--- a/src/stubs/view-index.stub
+++ b/src/stubs/view-index.stub
@@ -32,7 +32,7 @@
@foreach($masters as $key => $master)
- | {{ 1 + $key }} |
+ {{ $items->firstItem() + $key }} |
{{ $master->name }} |
{{ $master->description }} |
@@ -53,6 +53,7 @@
@endforeach
|
+ {{ $masters->appends(Request::except('page'))->render() }}
diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php
index dd5c1cc..617e83e 100644
--- a/tests/Generators/ControllerGeneratorTest.php
+++ b/tests/Generators/ControllerGeneratorTest.php
@@ -29,7 +29,9 @@ class ItemsController extends Controller
public function index()
{
\$editableItem = null;
- \$items = Item::paginate(25);
+ \$items = Item::where(function (\$query) {
+ \$query->where('name', 'like', '%'.request('q').'%');
+ })->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
\$editableItem = Item::find(request('id'));
@@ -48,7 +50,7 @@ class ItemsController extends Controller
{
\$this->validate(\$request, [
'name' => 'required|max:60',
- 'description' => 'required|max:255',
+ 'description' => 'nullable|max:255',
]);
Item::create(\$request->only('name', 'description'));
@@ -67,7 +69,7 @@ class ItemsController extends Controller
{
\$this->validate(\$request, [
'name' => 'required|max:60',
- 'description' => 'required|max:255',
+ 'description' => 'nullable|max:255',
]);
\$routeParam = request()->only('page', 'q');
diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php
index 360401c..0dfd598 100644
--- a/tests/Generators/FeatureTestGeneratorTest.php
+++ b/tests/Generators/FeatureTestGeneratorTest.php
@@ -100,7 +100,7 @@ class ManageItemsTest extends TestCase
public function user_can_edit_a_item_within_search_query()
{
\$this->loginAsUser();
- \$item = factory(Item::class)->create(['description' => 'Testing 123']);
+ \$item = factory(Item::class)->create(['name' => 'Testing 123']);
\$this->visit(route('items.index', ['q' => '123']));
\$this->click('edit-item-'.\$item->id);
diff --git a/tests/Generators/MigrationGeneratorTest.php b/tests/Generators/MigrationGeneratorTest.php
index 89bad16..9c84e9b 100644
--- a/tests/Generators/MigrationGeneratorTest.php
+++ b/tests/Generators/MigrationGeneratorTest.php
@@ -31,7 +31,7 @@ class CreateItemsTable extends Migration
Schema::create('items', function (Blueprint \$table) {
\$table->increments('id');
\$table->string('name', 60);
- \$table->string('description');
+ \$table->string('description')->nullable();
\$table->timestamps();
});
}
diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php
index 315cb5c..92f1dd2 100644
--- a/tests/Generators/ViewsGeneratorTest.php
+++ b/tests/Generators/ViewsGeneratorTest.php
@@ -47,7 +47,7 @@ class ViewsGeneratorTest extends TestCase
@foreach(\$items as \$key => \$item)
- | {{ 1 + \$key }} |
+ {{ \$items->firstItem() + \$key }} |
{{ \$item->name }} |
{{ \$item->description }} |
@@ -68,6 +68,7 @@ class ViewsGeneratorTest extends TestCase
@endforeach
|
+
{{ \$items->appends(Request::except('page'))->render() }}
@@ -88,16 +89,15 @@ class ViewsGeneratorTest extends TestCase
$this->assertFileExists($formViewPath);
$formViewContent = "@if (Request::get('action') == 'create')
{!! Form::open(['route' => 'items.store']) !!}
- {!! FormField::text('name') !!}
+ {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('item.create'), ['class' => 'btn btn-success']) !!}
- {!! Form::hidden('cat', 'item') !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'edit' && \$editableItem)
{!! Form::model(\$editableItem, ['route' => ['items.update', \$editableItem->id],'method' => 'patch']) !!}
- {!! FormField::text('name') !!}
+ {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!}
@if (request('q'))
{{ Form::hidden('q', request('q')) }}