PHP code example of marshmallow / nova-user-groups
1. Go to this page and download the library: Download marshmallow/nova-user-groups library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marshmallow / nova-user-groups example snippets
namespace App\Models;
use Marshmallow\NovaUserGroups\Traits\HasUserGroup;
class User extends Authenticatable
{
use HasUserGroup;
// ...
}
namespace App\Nova;
use Laravel\Nova\Resource as NovaResource;
use Laravel\Nova\Http\Requests\NovaRequest;
use Marshmallow\NovaUserGroups\Traits\UserGroupResource;
abstract class Resource extends NovaResource
{
use UserGroupResource;
// ...
}
// app/models/user.php
namespace App\Models;
class User extends Authenticatable
{
/**
* Please not that the methods must start with `may` and
* then start with a capital letter.
*/
public function mayImpersonate()
{
return $this->allowedToRunMethod('impersonate');
}
}
namespace App\Providers;
// ..
use Marshmallow\NovaUserGroups\Traits\UserGroupNovaServiceProvider;
class NovaServiceProvider extends NovaApplicationServiceProvider
{
use UserGroupNovaServiceProvider;
// ...
protected function cards()
{
return $this->canSeeCards([
// Your cards go here.
]);
}
protected function dashboards()
{
return $this->canSeeDashboards([
// Your cards go here.
]);
}
protected function tools()
{
return $this->canSeeTools([
// Your cards go here.
]);
}
}
return [
/*
|--------------------------------------------------------------------------
| Allowed Admin Groups
|--------------------------------------------------------------------------
|
| This is a list of groups on which the methods will be defined.
|
*/
'groups' => [
'admin' => 'Administrator',
'super-admin' => 'SuperAdministrator',
],
/*
|--------------------------------------------------------------------------
| Allowed Methods
|--------------------------------------------------------------------------
|
| This is a list of allowed methods per group
|
*/
'methods' => [
'admin' => [
'viewNova',
],
'super-admin' => [
'viewNova',
'viewTelescope',
'viewHorizon'
]
],
];
## Commands