Rumah > Soal Jawab > teks badan
P粉4712073022023-07-27 13:42:45
Berdasarkan penjelasan anda, saya melakukannya seperti berikut:
Jadual****************
jadual_projek_pengguna:
Schema::create('project_user', function (Blueprint $table) { $table->unsignedBigInteger('project_id'); $table->unsignedBigInteger('user_id'); });
jadual_permission_role:
Schema::create('permission_role', function (Blueprint $table) { $table->unsignedBigInteger('permission_id'); $table->unsignedBigInteger('role_id'); });
role_user table:
Schema::create('role_user', function (Blueprint $table) { $table->unsignedBigInteger('role_id'); $table->unsignedBigInteger('user_id'); });
Model *************
Model Pengguna:
/** * Team Relationship * * @return BelongsToMany */ public function teams(): BelongsToMany { return $this->belongsToMany(Team::class); } /** * Project Relationship * * @return BelongsToMany */ public function projects(): BelongsToMany { return $this->belongsToMany(Project::class); } /** * Role Relationship * * @return BelongsToMany */ public function roles(): BelongsToMany { return $this->belongsToMany(Role::class, 'role_user'); }
Model Pasukan:
/** * User Relationship * * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(User::class); } /** * Project Relationship * * @return HasMany */ public function projects(): HasMany { return $this->hasMany(Project::class); }
Model Projek:
/** * Team Relation * * @return BelongsTo */ public function team(): BelongsTo { return $this->belongsTo(Team::class); } /** * User Relation * * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(User::class); }
Role Model:
/** * Permission Relation * * @return BelongsToMany */ public function permissions(): BelongsToMany { return $this->belongsToMany(Permission::class, 'permission_role'); } /** * User Relation * * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(User::class,'role_user'); }
Model Kebenaran:
Firsreeetcipta peranan yang kita kehendaki. Contohnya:
Peranan 1: Nama = Pentadbir Super, Jenis = Pengguna
Peranan 2: Nama = Ketua Pasukan, Jenis = Pasukan
Peranan 3: Nama = Pembangun Projek, Jenis = Projek
Sekarang, kami akan mengharapkan peranan diberikan kepada pengguna kami. Peranan ini disimpan dalam jadual role_user.
Kemudian, berdasarkan peranan ini, anda boleh menentukan tanggungjawab setiap pengguna dalam setiap projek dan pasukan.