GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / multitenancynovatool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from romegasoftware/multitenancynovatool

2.0 0.0 0.0 392 KB

Integrates the Multitenancy package into Laravel's Nova

PHP 90.59% Blade 9.41%

multitenancynovatool's Introduction

Multitenancy Nova Tool

Total Downloads

This package is meant to integrate with the Multitenancy Package to bring multitenancy functionality and management to Laravel's Nova.

This package automatically includes the Multitenancy Package as a dependency. Please read the documentation on how to integrate it with your existing app.

index

create

Installation

Install the package via Composer:

composer require jeffersonsimaogoncalves/multitenancy-nova-tool

Then follow the Installation instructions to set up the Multitenancy Package.

Next, you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \JeffersonSimaoGoncalves\MultitenancyNovaTool\MultitenancyNovaTool,
    ];
}

This package requires Super Administrator or access admin permissions. This can be added either through the included permission management tool under "Roles & Permissions" or through our assign super-admin command.

Hint If you already executed multitenancy:install, a role with the name Super Administrator and a permission access admin attached was already created. Therefore you only need to add the role to a user.

php artisan multitenancy:super-admin [email protected]

Usage

New menu items labelled "Multitenancy" and "Roles & Permissions" will appear in your Nova app after installing this package.

To see the Tenant relation in the user detail view, add a BelongsToMany field to your app/Nova/User resource:

// in app/Nova/User.php

use Laravel\Nova\Fields\BelongsToMany;

public function fields(Request $request)
{
    return [
        // ...
        BelongsToMany::make('Tenants', 'tenants', \JeffersonSimaoGoncalves\MultitenancyNovaTool\Tenant::class),
    ];
}

On each Nova resource that is tenantable, a BelongsTo field is required in order to see the relation to the Tenant model:

use Laravel\Nova\Fields\BelongsTo;

public function fields(Request $request)
{
    return [
        // ...
        BelongsTo::make('Tenants', 'tenant', \JeffersonSimaoGoncalves\MultitenancyNovaTool\Tenant::class),
    ];
}

Define Inverse Relationships

In order to display all related data to the Tenant model, you need to first implement a Tenant model that extends the package's provided model.

// in app/Tenant.php

namespace App;

use JeffersonSimaoGoncalves\Multitenancy\Models\Tenant as TenantModel;

class Tenant extends TenantModel
{
  // ... define relationships
    public function products()
    {
        return $this->hasMany(\App\Product::class);
    }
}

Next, update your config file to point to your new model.

// in config/multitenancy.php

// ...
'tenant_model' => \App\Tenant::class,

Then create a Tenant Nova resource that extends the package's resource.

// in app/Nova/Tenant.php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\HasMany;
use JeffersonSimaoGoncalves\MultitenancyNovaTool\Tenant as TenantResource;

class Tenant extends TenantResource
{
    public static $model = \App\Tenant::class;

    /**
    * Get the fields displayed by the resource.
    *
    * @param  \Illuminate\Http\Request  $request
    * @return array
    */
    public function fields(Request $request)
    {
        return array_merge(parent::fields($request),
        [
            // ... define relationships
            HasMany::make('Products'),
        ]);
    }

}

Middleware

To scope Nova results to the Tenant being utilized, add the middleware to Nova:

// in config/nova.php

// ...

'middleware' => [
    // ...
    \JeffersonSimaoGoncalves\Multitenancy\Middleware\TenantMiddleware::class,
],

Accessing Nova at the admin subdomain will remove scopes and display all results. Only users given the correct permissions, such as Super Administrator, will be able to access this subdomain.

Policies

By default, the Multitenancy resource will only be visible on the admin subdomain to users with appropriate access to this subdomain. You may override the policy to allow more access to the resource by defining a policy within your project. And then within your AuthServiceProvider, register the policy:

// in app/Providers/AuthServiceProvider.php

// ...
protected $policies = [
  // ...
    \JeffersonSimaoGoncalves\Multitenancy\Models\Tenant::class => \App\Policies\TenantPolicy::class,
];

You can override the Permission and Role model policies by setting the policy file up in you config/multitenancy.php file. Look for policies.role and policies.permission.

Reporting Issues

If you have a problem with this plugin or any bug, please open an issue on GitHub.

Credits

This work is based on the code by RomegaDigital.

multitenancynovatool's People

Contributors

bradenkeith avatar jeffersonsimaogoncalves avatar naoray avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.