feat: Implement user-branch relationship and update user management views

- Added a many-to-many relationship between users and branches in User model.
- Updated user creation and editing views to support multiple branch selection.
- Modified user index view to display associated branches.
- Created UserBranch model to manage user-branch associations.
- Added migration for user_branches table with foreign key constraints.
- Implemented seeder to populate user_branches based on existing user branch data.

Run this command:
- php artisan migrate
- php artisan module:seed Usermanagement --class=UserBranchesSeeder
This commit is contained in:
Sholahuddin Al Ayubi
2025-12-11 17:20:34 +07:00
parent f3872e0665
commit 0b28760f41
7 changed files with 666 additions and 531 deletions

View File

@@ -0,0 +1,34 @@
<?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::create('user_branches', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('branch_id');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('branch_id')->references('id')->on('branches')->onDelete('cascade');
$table->unique(['user_id', 'branch_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_branches');
}
};