Skip to content

Commit

Permalink
Nova User Management
Browse files Browse the repository at this point in the history
update for laravel nova 3
  • Loading branch information
anditsung committed May 19, 2020
1 parent 7a2848d commit d9ee541
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions src/Nova/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
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;
use Laravel\Nova\Fields\Text;
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
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 6 additions & 5 deletions src/Nova/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 6 additions & 5 deletions src/Stub/Nova/User.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ),

Expand Down

0 comments on commit d9ee541

Please sign in to comment.