Skip to content

Commit 50b9a37

Browse files
committed
Add Correct Default Value According To Field Type
1 parent f38629a commit 50b9a37

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

app/Crud/CouponCrud.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class CouponCrud extends CrudService
101101
*/
102102
public $fillable = [];
103103

104+
public $skippable = [ 'products', 'categories' ];
105+
104106
/**
105107
* Define Constructor
106108
* @param

app/Services/CrudService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,12 @@ public function getFlatForm( $crud, $fields, $model = null )
883883
*/
884884
if ( ! in_array( $tabKey, $keys ) ) {
885885
foreach( $tab[ 'fields' ] as $field ) {
886-
$data[ $field[ 'name' ] ] = data_get( $fields, $tabKey . '.' . $field[ 'name' ] );
886+
switch( $field[ 'type' ] ) {
887+
case 'number': $defaultValue = 0; break;
888+
default: $defaultValue = ''; break;
889+
}
890+
891+
$data[ $field[ 'name' ] ] = data_get( $fields, $tabKey . '.' . $field[ 'name' ] ) ?: $defaultValue;
887892
}
888893
}
889894
}

public/js/popups.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/CreateCouponTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function testCreateCoupon()
5050
]
5151
]);
5252

53+
$response->dump();
5354
$response->assertJsonPath( 'status', 'success' );
5455
}
5556
}

0 commit comments

Comments
 (0)