added full module support

This commit is contained in:
Mark Gregory
2026-06-10 12:42:07 +01:00
parent 12d4eec076
commit c59b16d791
63 changed files with 1639 additions and 131 deletions
+25 -7
View File
@@ -5,29 +5,47 @@ namespace App\Actions\Fortify;
use App\Concerns\PasswordValidationRules;
use App\Concerns\ProfileValidationRules;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Modules\Platform\app\Models\Company;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules, ProfileValidationRules;
/**
* Validate and create a newly registered user.
* Validate and create a newly registered user with an isolated company tenant.
*
* @param array<string, string> $input
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
...$this->profileRules(),
'password' => $this->passwordRules(),
'company_name' => ['nullable', 'string', 'max:255'],
])->validate();
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => $input['password'],
]);
return DB::transaction(function () use ($input): User {
$companyName = $input['company_name'] ?? ($input['name'] . ' Company');
$company = Company::create([
'name' => $companyName,
'slug' => Str::slug($companyName . '-' . Str::random(6)),
'status' => 'active',
'timezone' => 'Europe/London',
]);
return User::create([
'company_id' => $company->id,
'name' => $input['name'],
'email' => $input['email'],
'password' => $input['password'],
'is_company_admin' => true,
'status' => 'active',
]);
});
}
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class Company extends \Modules\Platform\app\Models\Company
{
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class LicenseKey extends \Modules\Platform\app\Models\LicenseKey
{
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class Payment extends \Modules\Platform\app\Models\Payment
{
}
+22 -15
View File
@@ -2,47 +2,54 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Spatie\Permission\Traits\HasRoles;
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
class User extends Authenticatable implements PasskeyUser
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
use HasFactory, HasRoles, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
protected $fillable = [
'company_id', 'name', 'email', 'password', 'is_platform_admin', 'is_company_admin', 'status',
];
protected $hidden = ['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'is_platform_admin' => 'boolean',
'is_company_admin' => 'boolean',
];
}
/**
* Get the user's initials
*/
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
public function initials(): string
{
return Str::of($this->name)
->explode(' ')
->take(2)
->map(fn ($word) => Str::substr($word, 0, 1))
->map(fn ($word) => Str::substr((string) $word, 0, 1))
->implode('');
}
public function isMpbaPlatformAdmin(): bool
{
return $this->is_platform_admin && $this->company?->is_system_company === true;
}
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class Warehouse extends \Modules\Warehouse\app\Models\Warehouse
{
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class WarehouseValidationRule extends \Modules\Warehouse\app\Models\WarehouseValidationRule
{
}