Skip to content

Commit

Permalink
Moox User init w-i-p (#381)
Browse files Browse the repository at this point in the history
Co-authored-by: adrolli <[email protected]>
  • Loading branch information
adrolli and adrolli authored Mar 6, 2024
1 parent cc76fd5 commit f07fa2c
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 413 deletions.
2 changes: 1 addition & 1 deletion config/filament-shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'shield_resource' => [
'should_register_navigation' => true,
'slug' => 'user/roles',
'navigation_sort' => 10,
'navigation_sort' => 702,
'navigation_badge' => true,
'navigation_group' => true,
'is_globally_searchable' => false,
Expand Down
64 changes: 64 additions & 0 deletions database/migrations/2024_03_04_235738_update_user_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// name and email are part of Laravel's default
if (! Schema::hasColumn('users', 'slug')) {
$table->string('slug')->after('name');
}
if (! Schema::hasColumn('users', 'gender')) {
$table->enum('gender', ['male', 'female', 'other'])->after('slug');
}
if (! Schema::hasColumn('users', 'title')) {
$table->string('title')->nullable()->after('gender');
}
if (! Schema::hasColumn('users', 'first_name')) {
$table->string('first_name')->after('title');
}
if (! Schema::hasColumn('users', 'last_name')) {
$table->string('last_name')->after('first_name');
}
if (! Schema::hasColumn('users', 'website')) {
$table->string('website')->nullable()->after('email');
}
if (! Schema::hasColumn('users', 'description')) {
$table->text('description')->nullable()->after('website');
}
// `email_verified_at`, `password`, and `remember_token` are part of Laravel's default
if (! Schema::hasColumn('users', 'two_factor_secret')) {
$table->text('two_factor_secret')->nullable()->after('remember_token');
}
if (! Schema::hasColumn('users', 'two_factor_recovery_codes')) {
$table->text('two_factor_recovery_codes')->nullable()->after('two_factor_secret');
}
if (! Schema::hasColumn('users', 'two_factor_confirmed_at')) {
$table->timestamp('two_factor_confirmed_at')->nullable()->after('two_factor_recovery_codes');
}
// Skipping `current_team_id` as it's from Jetstream
if (! Schema::hasColumn('users', 'avatar_url')) {
$table->string('avatar_url', 2048)->nullable()->after('two_factor_confirmed_at');
}
if (! Schema::hasColumn('users', 'profile_photo_path')) {
$table->string('profile_photo_path')->nullable()->after('avatar_url');
}
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
// Sorry, it's the user table
}
};
2 changes: 1 addition & 1 deletion packages/builder/src/Resources/BuilderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BuilderResource extends Resource
{
protected static ?string $model = Builder::class;

protected static ?string $navigationIcon = 'heroicon-o-play';
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
Expand Down
17 changes: 1 addition & 16 deletions packages/user/config/user.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<?php

return [
'resources' => [
'user' => [
'enabled' => true,
'label' => 'User',
'plural_label' => 'Users',
'navigation_group' => 'User Group',
'navigation_icon' => 'heroicon-o-play',
'navigation_sort' => 1,
'navigation_count_badge' => true,
'resource' => Moox\User\Resources\UserResource::class,
],
],
'pruning' => [
'enabled' => true,
'retention_days' => 7,
],
// not used
];
32 changes: 0 additions & 32 deletions packages/user/database/migrations/create_user_table.php.stub

This file was deleted.

63 changes: 63 additions & 0 deletions packages/user/database/migrations/update_user_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// name and email are part of Laravel's default
if (!Schema::hasColumn('users', 'slug')) {
$table->string('slug')->after('name');
}
if (!Schema::hasColumn('users', 'gender')) {
$table->enum('gender', ['unknown', 'male', 'female', 'other'])->after('slug')->default('unknown');
}
if (!Schema::hasColumn('users', 'title')) {
$table->string('title')->nullable()->after('gender');
}
if (!Schema::hasColumn('users', 'first_name')) {
$table->string('first_name')->after('title');
}
if (!Schema::hasColumn('users', 'last_name')) {
$table->string('last_name')->after('first_name');
}
if (!Schema::hasColumn('users', 'website')) {
$table->string('website')->nullable()->after('email');
}
if (!Schema::hasColumn('users', 'description')) {
$table->text('description')->nullable()->after('website');
}
// `email_verified_at`, `password`, and `remember_token` are part of Laravel's default
if (!Schema::hasColumn('users', 'two_factor_secret')) {
$table->text('two_factor_secret')->nullable()->after('remember_token');
}
if (!Schema::hasColumn('users', 'two_factor_recovery_codes')) {
$table->text('two_factor_recovery_codes')->nullable()->after('two_factor_secret');
}
if (!Schema::hasColumn('users', 'two_factor_confirmed_at')) {
$table->timestamp('two_factor_confirmed_at')->nullable()->after('two_factor_recovery_codes');
}
// Skipping `current_team_id` as it's from Jetstream
if (!Schema::hasColumn('users', 'avatar_url')) {
$table->string('avatar_url', 2048)->nullable()->after('two_factor_confirmed_at');
}
if (!Schema::hasColumn('users', 'profile_photo_path')) {
$table->string('profile_photo_path')->nullable()->after('avatar_url');
}
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
// Sorry, it's the user table
}
};
4 changes: 3 additions & 1 deletion packages/user/resources/lang/en/translations.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

return [
'single' => 'User',
'plural' => 'Users',
'breadcrumb' => 'User',
'title' => 'User',
'navigation_label' => 'User',
'navigation_group' => 'User Group',
'navigation_group' => 'User',
'totalone' => 'User One',
'totaltwo' => 'User Two',
'totalthree' => 'User Three',
Expand Down
10 changes: 6 additions & 4 deletions packages/user/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ public function publish_configuration(): void
public function publish_migrations(): void
{
if (Schema::hasTable('user')) {
warning('The user table already exists. The migrations will not be published.');
} elseif (confirm('Do you wish to publish the migrations?', true)) {
info('Publishing User Migrations...');
$this->callSilent('vendor:publish', ['--tag' => 'user-migrations']);
warning('The user table already exists. The migrations add fields required by Moox User.');

if (confirm('Do you wish to publish the migrations?', true)) {
info('Publishing User Migrations...');
$this->callSilent('vendor:publish', ['--tag' => 'user-migrations']);
}
}
}

Expand Down
38 changes: 29 additions & 9 deletions packages/user/src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@

namespace Moox\User\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\User as BaseUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Jeffgreco13\FilamentBreezy\Traits\TwoFactorAuthenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Model
class User extends BaseUser
{
protected $table = 'user';
use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;

protected $fillable = [
'name',
'started_at',
'finished_at',
'failed',
'slug',
'gender',
'title',
'first_name',
'last_name',
'email',
'website',
'description',
'password',
'profile_photo_path',
];

protected $searchableFields = ['*'];

protected $hidden = [
'password',
'remember_token',
'two_factor_secret',
'two_factor_recovery_codes',
];

protected $casts = [
'failed' => 'bool',
'started_at' => 'datetime',
'finished_at' => 'datetime',
'email_verified_at' => 'datetime',
'two_factor_confirmed_at' => 'datetime',
];
}
Loading

0 comments on commit f07fa2c

Please sign in to comment.