diff --git a/composer.json b/composer.json index 9d722a6..34e848b 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ ], "license": "MIT", "require": { - "php": ">=7.1.0", - "laravel/nova": "^2", - "spatie/laravel-permission": "^3", - "outhebox/nova-hidden-field": "^1.0" + "php": "^7.2.5", + "laravel/framework": "^7.0", + "laravel/nova": "^3", + "spatie/laravel-permission": "^3" }, "autoload": { "psr-4": { diff --git a/src/Nova/Permission.php b/src/Nova/Permission.php index ee48668..de0fbf0 100644 --- a/src/Nova/Permission.php +++ b/src/Nova/Permission.php @@ -8,6 +8,7 @@ use Illuminate\Http\Request; use Illuminate\Validation\Rule; use Laravel\Nova\Fields\BelongsToMany; +use Laravel\Nova\Fields\Hidden; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Select; @@ -15,7 +16,6 @@ use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Nova; -use Outhebox\NovaHiddenField\HiddenField; use Tsung\NovaUserManagement\Models\Permission as PermissionModel; class Permission extends ResourceForUser @@ -96,9 +96,9 @@ public function fields(Request $request) ->rules(['required', Rule::in($guardOptions)]) ->hideFromIndex(), - HiddenField::make('User', 'user_id') - ->current_user_id() - ->onlyOnForms(), + Hidden::make('User', 'user_id')->default(function($request) { + return $request->user()->id; + }), BelongsTo::make(_('Created By'), 'user', User::class) ->onlyOnDetail(), diff --git a/src/Nova/Role.php b/src/Nova/Role.php index 6c3baf2..5dbae6a 100644 --- a/src/Nova/Role.php +++ b/src/Nova/Role.php @@ -9,11 +9,11 @@ use Illuminate\Validation\Rule; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\Boolean; +use Laravel\Nova\Fields\Hidden; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Select; use Laravel\Nova\Fields\Text; -use Outhebox\NovaHiddenField\HiddenField; use Tsung\NovaUserManagement\Fields\PermissionCheckbox; use Tsung\NovaUserManagement\Models\Role as RoleModel; use Laravel\Nova\Nova; @@ -71,11 +71,12 @@ public function fields(Request $request) ->options($guardOptions->toArray()) ->rules(['required', Rule::in($guardOptions)]), - Boolean::make('Active', 'is_active'), + Boolean::make('Active', 'is_active') + ->default(true), - HiddenField::make('User', 'user_id') - ->current_user_id() - ->onlyOnForms(), + Hidden::make('User', 'user_id')->default(function($request) { + return $request->user()->id; + }), BelongsTo::make(_('Created By'), 'user', User::class) ->onlyOnDetail(), diff --git a/src/Stub/Nova/User.stub b/src/Stub/Nova/User.stub index 7c1cdd7..573328f 100644 --- a/src/Stub/Nova/User.stub +++ b/src/Stub/Nova/User.stub @@ -4,13 +4,13 @@ namespace App\Nova; use Illuminate\Http\Request; +use Laravel\Nova\Fields\Hidden; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Password; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\Boolean; -use Outhebox\NovaHiddenField\HiddenField; use Tsung\NovaUserManagement\Nova\ResourceForUser; use Tsung\NovaUserManagement\Nova\Role; use Tsung\NovaUserManagement\Nova\Permission; @@ -68,14 +68,15 @@ class User extends ResourceForUser ->creationRules('required', 'string', 'min:8') ->updateRules('nullable', 'string', 'min:8'), - HiddenField::make('User', 'user_id') - ->current_user_id() - ->onlyOnForms(), + Hidden::make('User', 'user_id')->default(function($request) { + return $request->user()->id; + }), BelongsTo::make(_('Created By'), 'user', User::class) ->onlyOnDetail(), - Boolean::make('Active', 'is_active'), + Boolean::make('Active', 'is_active') + ->default(true), MorphToMany::make(__('Roles'), 'roles', Role::class ),