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:
34
app/Models/UserBranch.php
Normal file
34
app/Models/UserBranch.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Usermanagement\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
|
||||
// use Modules\Usermanagement\Database\Factories\UserBranchFactory;
|
||||
|
||||
class UserBranch extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $table = 'user_branches';
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'branch_id',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function branch()
|
||||
{
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user