Skip to content

Commit

Permalink
Merge pull request #166 from Sellist-lk/team-configuration-implementa…
Browse files Browse the repository at this point in the history
…tion

Team configuration implementation
  • Loading branch information
curtisdelicata authored Aug 29, 2024
2 parents b825c87 + 321da52 commit 3332a65
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 20 deletions.
64 changes: 64 additions & 0 deletions app/Filament/App/Resources/UserResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Filament\App\Resources;

use App\Filament\App\Resources\UserResource\Pages;
use App\Filament\App\Resources\UserResource\RelationManagers;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class UserResource extends Resource
{
protected static ?string $model = User::class;

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

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}
12 changes: 12 additions & 0 deletions app/Filament/App/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Filament\App\Resources\UserResource\Pages;

use App\Filament\App\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/App/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\App\Resources\UserResource\Pages;

use App\Filament\App\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/App/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\App\Resources\UserResource\Pages;

use App\Filament\App\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ public function up()
{
Schema::create('site_settings', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('currency');
$table->string('default_language');
$table->text('address');
$table->string('country');
$table->string('email');
$table->string('name')->nullable();
$table->string('currency')->nullable();
$table->string('default_language')->nullable();
$table->text('address')->nullable();
$table->string('country')->nullable();
$table->string('email')->nullable();
$table->string('phone_01')->nullable();
$table->string('phone_02')->nullable();
$table->string('phone_03')->nullable();
$table->string('phone_04')->nullable();
$table->string('facebook')->nullable();
$table->string('twitter')->nullable();
$table->string('github')->nullable();
$table->string('youtube')->nullable();
$table->decimal('sales_commission_percentage', 5, 2)->default(1.00);
$table->decimal('lettings_commission_percentage', 5, 2)->default(8.00);
$table->timestamps();
});
}
Expand Down
11 changes: 6 additions & 5 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
// User::factory(10)->withPersonalTeam()->create();

User::factory()->withPersonalTeam()->create([
'name' => 'Test User',
'email' => '[email protected]',
$this->call([
SiteSettingsSeeder::class,
MenuSeeder::class,
RolesSeeder::class,
TeamSeeder::class,
UserSeeder::class,
]);
}
}
10 changes: 5 additions & 5 deletions database/seeders/RolesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class RolesSeeder extends Seeder
*/
public function run(): void
{
$adminRole = Role::firstOrCreate(['name' => 'admin']);
$roles = ['admin', 'staff', 'client', 'free'];
$permissions = Permission::where('guard_name', 'web')->pluck('id')->toArray();
$adminRole->syncPermissions($permissions);

$freeRole = Role::firstOrCreate(['name' => 'free']);
$freePermissions = Permission::where('guard_name', 'web')->pluck('id')->toArray();
$freeRole->syncPermissions($freePermissions);
foreach ($roles as $roleName) {
$role = Role::firstOrCreate(['name' => $roleName]);
$role->syncPermissions($permissions);
}
}
}
12 changes: 10 additions & 2 deletions database/seeders/SiteSettingsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ class SiteSettingsSeeder extends Seeder
public function run()
{
SiteSettings::create([
'name' => config('app.name', 'Liberu Real Estate'),
'name' => config('app.name', 'Liberu '),
'currency' => '£',
'default_language' => 'en',
'address' => '123 Real Estate St, London, UK',
'address' => '123 St, London, UK',
'country' => 'United Kingdom',
'email' => '[email protected]',
'phone_01' => '+44 123 456 7890',
'phone_02' => '+44 123 456 7890',
'phone_03' => '+44 123 456 7890',
'phone_04' => '+44 123 456 7890',
'facebook' => 'https://facebook.com/liberusoftware',
'twitter' => 'https://twitter.com/liberusoftware',
'github' => 'https://Github.com/liberusoftware',
'youtube' => 'https://YouTube.com/@liberusoftware',
]);
}
}
23 changes: 23 additions & 0 deletions database/seeders/TeamSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Database\Seeders;

use App\Models\Team;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class TeamSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$team = Team::create([
'id' => 1,
'name' => 'default',
'personal_team' => false,
'user_id' => 1,
]);
}
}
47 changes: 47 additions & 0 deletions database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Database\Seeders;

use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$adminUser = User::create([
'name' => 'Admin User',
'email' => '[email protected]',
'password' => Hash::make('password'),
'email_verified_at' => now(),
]);
$adminUser->assignRole('admin');

$staffUser = User::create([
'name' => 'Staff User',
'email' => '[email protected]',
'password' => Hash::make('password'),
'email_verified_at' => now(),
]);
$staffUser->assignRole('staff');

// Create teams for admin and staff users
$this->createTeamForUser($adminUser);
$this->createTeamForUser($staffUser);
}

private function createTeamForUser($user)
{
$team = Team::first();
$team->users()->attach($user);

$user->current_team_id = 1;
$user->save();
}
}
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

Route::get('/', fn () => view('welcome'));

Route::redirect('/login', '/app/login')->name('login');
// Route::redirect('/login', '/app/login')->name('login');

Route::redirect('/register', '/app/register')->name('register');
// Route::redirect('/register', '/app/register')->name('register');

Route::redirect('/dashboard', '/app')->name('dashboard');

Expand Down

0 comments on commit 3332a65

Please sign in to comment.