PHP code example of romegadigital / multitenancy-nova-tool
1. Go to this page and download the library: Download romegadigital/multitenancy-nova-tool 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/ */
romegadigital / multitenancy-nova-tool example snippets
// in app/Providers/NovaServiceProvider.php
public function tools()
{
return [
// ...
new \RomegaDigital\MultitenancyNovaTool\MultitenancyNovaTool,
];
}
// in app/Nova/User.php
use Laravel\Nova\Fields\BelongsToMany;
public function fields(Request $request)
{
return [
// ...
BelongsToMany::make('Tenants', 'tenants', \RomegaDigital\MultitenancyNovaTool\Tenant::class),
];
}
use Laravel\Nova\Fields\BelongsTo;
public function fields(Request $request)
{
return [
// ...
BelongsTo::make('Tenants', 'tenant', \RomegaDigital\MultitenancyNovaTool\Tenant::class),
];
}
// in app/Tenant.php
namespace App\Models;
use RomegaDigital\Multitenancy\Models\Tenant as TenantModel;
class Tenant extends TenantModel
{
// ... define relationships
public function products()
{
return $this->hasMany(\App\Product::class);
}
}
// in config/multitenancy.php
// ...
'tenant_model' => \App\Models\Tenant::class,
// in app/Nova/Tenant.php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\HasMany;
use RomegaDigital\MultitenancyNovaTool\Tenant as TenantResource;
class Tenant extends TenantResource
{
public static $model = \App\Models\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'),
]);
}
}